VBA:获取相对于特定范围的活动单元格位置?

时间:2013-10-29 04:38:09

标签: vba excel-vba excel

说我有dim range B2:E7。如何找出相对于范围的活动单元格的坐标?

1 个答案:

答案 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

将行替换为行以获得相同的行。