简体   繁体   English

如何选择直到最后一个非空单元格的列

[英]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.

相关问题 选择 A 列中的最后一个非空单元格 --> 根据 C 列中的最后一个非空单元格填充 A 列下方的空单元格 --> 重复 - Select last non-empty cell in column A --> Fill down empty cells below in column A, based on last non-empty cell in column C --> Repeat 列中的最后一个非空单元格 - Last non-empty cell in a column Excel - 计算列中的空单元格,直到找到非空单元格报告然后继续向下列直到找到下一个非空单元格 - Excel - Count Empty Cells in a Column until a Non Empty Cell is Found Report then Continue down column till next non empty cell is found 有没有办法选择第一个空单元格上方的公式并向下粘贴直到最后一个完整单元格? - Is there a way to select the formula above the first empty cell and paste downwards till the last full cell? 如何自动填充活动单元格的列直到最后一行 - How to auto fill the column of the active cell till the last row 如何将某些单元格中的范围复制到某个列中的最后一个非空单元格 - How to copy range from certain cell to last non empty cell in certain column 代码以找到excel列中连续非空单元格的总和,直到出现空单元格? - code to find the sum of continuous non-empty cells in a column in excel till the empty cell occurs? 选择excel范围内的最后一个非空单元格 - select the last non-empty cell in excel range 获取行中的最后一个非空单元格,或获取Excel中带有非空标题的最后一列 - Get last non-empty cell in a row or get last column with a non-empty header in Excel 列范围A到Z中的最后一个非空单元格 - Last non-empty cell from column range A to Z
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM