[英]how to select column till last non empty cell
I am creating vba macro to copy a column having set of values. 我正在创建vba宏来复制具有一组值的列。 but in between some rows are blank in that column.how to code it dynamically so that it will select till last non empty cell. 但是在该列中的某些行之间是空白。如何对其进行动态编码,以便它将选择直到最后一个非空单元格。
for example in cell A if A1 to A20 have values A21 is blank A22 to A35 have values A36,A37,A38 is blank A39 to A45 hav values 例如在单元格A中,如果A1到A20的值A21为空白A22到A35的值为A36,A37,A38为空白A39到A45的hav值
Now i need to dynamically select values from A1 to A45 and paste it in B. Also values in A Come through formula.I want to carry that formula and paste it as formula 现在我需要从A1到A45中动态选择值并将其粘贴到B中。另外,A值也应通过公式。我要携带该公式并将其粘贴为公式
how do i do it? 我该怎么做?
To work with all cells from A1 up to the last non-empty cell in column A: 要使用从A1到A列中最后一个非空单元格的所有单元格,请执行以下操作:
Dim oAllDataInA As Range
With Worksheets("Sheet1")
Set oAllDataInA =.Range("A1", .Range("A" & .Rows.Count).End(xlUp))
End With
'Now work with oAllDataInA. For instance. let formula in column B be same as in A:
oAllDataInA.Copy
oAllDataInA.Offset(,1).PasteSpecial xlFormulas
Please try the below code.. 请尝试以下代码。
Sub test() 'change the sheet name as yours Sheets("Sheet1").Activate Range("A1", Cells(Rows.Count, 1).End(xlUp)).Copy 'Change the destination range as yours Range("D1").Select Selection.PasteSpecial Paste:=xlPasteFormulas End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.