如何find被点击的button的单元坐标
我有一列所有行包含一个button执行相同的macros插入一个单击button上方的行。 但是,代码不起作用,因为macros不在单击button上方插入一行,而是在活动单元格所在的上方插入一行。
我应该如何修改代码,以便将行插入到被点击的button的正上方。
或者任何人都可以帮助识别点击button的组合。
Sub VBA_Tracker() Dim Origin As Range Set Origin = Sheet2.Cells(1, 1) Selection.EntireRow.Insert End Sub
在你的button代码中包含这样的行:
Sub Kommon() Dim sh As Shape Set sh = ActiveSheet.Shapes(Application.Caller) WhereAmI = sh.TopLeftCell.Address(0, 0) MsgBox Application.Caller & vbCrLf & WhereAmI End Sub
对于“表单风格”button:
每个形状都有一个TopLeftCell
属性。 这是形状所在的左上angular。 你可以这样findbutton行
a = button.TopLeftCell