这是你正在尝试的吗?我已经对代码进行了注释,以便您理解它不会有任何问题。
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long, lCol As Long
Dim rng As Range
'~~> Set this to the relevant worksheet
Set ws = [Sheet1]
With ws
'~~> Get the last row and last column
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
'~~> Set the range
Set rng = .Range(.Cells(lRow, 1), .Cells(lRow, lCol))
With rng
Debug.Print .Address
'
'~~> What ever you want to do with the address
'
End With
End With
End Sub
顺便说一句,我假设LastRow
所有行都相同,列也一样。如果不是这种情况,那么您将不得不使用.Find
查找最后一行和最后一列。你可能想看这个