首先,这不是典型的新手问题.我正在尝试找到我已经正确创建的范围中的最后一行(或单元格).
在这个例子中,我有两个范围合并为一个与union.在整个范围内循环,我得到了我想要的数据,并且工作得很好.
Sub Test()
Dim unionRange As Range, currentRow As Range
Set unionRange = Union(Range("A3:C5"), Range("A8:C11"))
For Each currentRow In unionRange.Rows
Debug.Print "Row: " & currentRow.row
Next currentRow
End Sub
Run Code Online (Sandbox Code Playgroud)
这给出了这些结果
Row: 3
Row: 4
Row: 5
Row: 8
Row: 9
Row: 10
Row: 11
Run Code Online (Sandbox Code Playgroud)
但是当我想确定当前行是否是我的范围中的最后一行时,我似乎无法找到获取该信息的干净方法.
Sub Test()
Dim unionRange As Range, currentRow As Range
Set unionRange = Union(Range("A3:C5"), Range("A8:C11"))
For Each currentRow In unionRange.Rows
Dim lastRowIndex As Integer
'lastRowIndex = unionRange. ???
If currentRow.row = lastRowIndex Then
MsgBox ("Last …Run Code Online (Sandbox Code Playgroud)