[英]VBA: getting the active cell position relative to a specific range?
假設我的dim range B2:E7
。 如何找到相對於范圍的活動單元格的坐標?
如果要獲取到活動單元格到范圍的距離,這將起作用:
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
將列替換為行以獲取與行相同的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.