将数据插入到button所在的同一行中

我创build了一个将数据从一个工作表复制到另一个的macros。 我想要一个广义的macros,它复制与button相同行号的数据,而不是代码中提到的B2

目前这段代码工作正常; button文本被更新并且MacroA已被分配给它。 我阅读了关于topleftcell ,但无法执行它。

 Sub MacroA() ' ' MacroA Macro ' Range("I2:J2").Select Selection.Copy Range("B2").Select Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True Range("D2").Select Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Activate ActiveSheet.Paste Application.CutCopyMode = False ActiveWorkbook.Save ActiveWindow.Close End Sub 

未经testing,但可能会帮助你…

 Sub Tester() Dim c As Range, sht As Worksheet Dim d As Range Set sht = ActiveSheet Set c = sht.Shapes(Application.Caller).TopLeftCell sht.Cells(c.Row, 2).Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True With ActiveSheet Set d = .Cells.Find(What:="", After:=.Range("D2"), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) sht.Range("I2:J2").Copy d .Parent.Save .Parent.Close End With Application.CutCopyMode = False End Sub