简体   繁体   English

Excel VBA-动态范围大小

[英]Excel VBA - Dynamic Range size

Im trying to find the range on a separate sheet. 我试图在另一张纸上找到范围。

Dim abc As Range
Dim size As Integer
size = Sheets("Misc").Cells(1, Sheets("Misc").Cells(1, 1).Rows.End(xlDown).Count)
abc = Sheets("Misc").Range("A1:A" & size)

Im struggling to get the 'size' to give me the count of the rows correctly. 我正在努力获取“大小”以正确地给我行数。 What am I doing wrong? 我究竟做错了什么?

You will need to Set the range. 您将需要Set范围。

dim sz as LONG
with Sheets("Misc")
    sz = .Cells(rows.count, 1).End(xlUp).Row
    SET abc = .Range("A1:A" & sz)
end with

The row number should be sufficient. 行号应该足够。 You don't really need a .Count for your purposes. 您实际上不需要.Count达到目的。 Just find the last populated row by looking from the bottom up. 只需从下往上查找,即可找到最后一个填充的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM