本文介绍了复制到最后一条数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以选择要复制到最后一个项目的范围?

 表格b $ b范围(A1:C200)。复制

'我的数据只能运行到E48,Im留下152个blanc。

现在它从A1复制到E200,但是如何编辑上面的代码,直到最后一块数据,在我的情况下是E48? (这是变量)



谢谢!



@Jean


$ b b

在我的excel表中,我有从A1-A18运行的数据,B是空的和C1-C2。现在我想复制所有包含一个值的单元格。

 使用范围(A1)
范围(.Cells(1,1),.End(xlDown) .Cells(20,3))。复制
结束于

A1-C20,但我只想要A1-A18和C1-C2看起来好像包含数据。但是它需要以这样的方式形成,一旦我有数据在B或我的范围扩展,这些也被复制。



这可能更清楚吗? / p>

关于复制/粘贴的情况;



我当前使用此

粘贴

  appWD.Selection.PasteSpecial'所以它也复制格式吗? 
'在你的情况下,你的意思是我应该这样做吗?
范围(.Cells(1,1),.End(xlDown).Cells(20,3))复制目标:appWD.Selection.PasteSpecial
pre>

解决方案

这样做:

 使用范围(A1)
范围(.Cells(1,1),.End(xlDown).Cells(1,5))复制
End With

如果您需要不同数量的列,请更改5。



此外,我学到了困难的方法:避免复制/粘贴,如果可能的话!复制和粘贴使用剪贴板。其他程序可能在代码运行时从剪贴板读取/写入剪贴板,这将导致不可预知的不可预测的结果。但是,可以安全地复制到同一行上的目标范围,例如:

  Range(.Cells ),.End(xlDown).Cells(1,5))。复制myDestinationRange 
 范围(.Cells(1,1),.End(xlDown).Cells(1,5))。 b $ b myDestinationRange.Paste 

后者使用剪贴板,而前者不使用。


Is it possible to select a range to copy to the last item?

Sheets("Design").Select
Range("A1:C200").Copy

'My data only runs until E48 and Im left with 152 blancs.

So now it copies from A1 to E200, but how can I edit the above code so it only selects until the last piece of data, which in my case is E48? (this is variable)

Thanks!

@Jean

In my excel sheet I have data running from A1-A18, B is empty and C1-C2. Now I would like to copy all the cells that contain a value.

 With Range("A1")
     Range(.Cells(1, 1), .End(xlDown).Cells(20, 3)).Copy
 End With

This will copy everything from A1-C20, but I only want A1-A18 and C1-C2 seen as though these contain data. But it needs to be formed in a way that once I have data in B or my range extends, that these get copied too.

Is this perhaps a bit clearer?

About the Copy/Paste situation;

I currently paste using this

appWD.Selection.PasteSpecial ' So it copies the formats too?
'In your case, do you mean I should do it like this?
Range(.Cells(1, 1), .End(xlDown).Cells(20, 3)).Copy Destination:=appWD.Selection.PasteSpecial
解决方案

This works:

With Range("A1")
    Range(.Cells(1, 1), .End(xlDown).Cells(1, 5)).Copy
End With

Change the "5" if you need a different number of columns.

Also, this I learned the hard way: Avoid Copy/Paste if at all possible! Copy and Paste use the clipboard. Other programs may read from / write to the clipboard while your code is running, which will cause wild, unpredictable results. However, it's safe to copy to your target range on the same line, i.e. do this

Range(.Cells(1, 1), .End(xlDown).Cells(1, 5)).Copy myDestinationRange

and not this

Range(.Cells(1, 1), .End(xlDown).Cells(1, 5)).Copy
myDestinationRange.Paste

The latter uses the clipboard while the former does not.

这篇关于复制到最后一条数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:30
查看更多