说我有dim range B2:E7
。如何找出相对于范围的活动单元格的坐标?
答案 0 :(得分:0)
如果你想从活动单元格到达范围的距离,这将起作用:
Sub colOffset()
Dim testRange As Range
Dim colLeft As Integer
Dim colRight As Integer
Set testRange = Range("B2:E7")
colLeft = testRange.Column
colRight = testRange.Column + testRange.Columns.Count - 1
MsgBox "column-offset to first column: " & ActiveCell.Column - colLeft
MsgBox "column-offset to last column: " & ActiveCell.Column - colRight
End Sub
将行替换为行以获得相同的行。