【发布时间】:2017-07-21 19:56:00
【问题描述】:
我正在使用一些代码,这些代码将 Excel 范围保存在变量中。我需要一种方法来找到这些范围变量的第一行和最后一行。如果可能的话,我宁愿不使用xlend(down).row 方法。我想我可以将它放入一个数组并获取 lbound 和 ubound 值,但这对于一个非常简单的任务来说似乎需要做很多工作。有什么简单的解决方法吗?
这是我的例子:
sub test()
dim r as range
dim x as integer
dim y as integer
set r as worksheets("sheet1").Range("A1:A7")
x = r.rows 'this gets me the first row in the range
y = r.lastrow 'this isn't valid, but I need something that will do the equivalent of this pseudo code
end sub
【问题讨论】:
-
r.cells(1).Row和r.cells(r.cells.count).row假设一个矩形单区域范围