0

我创建了一个宏,它将数据从一个工作表复制到另一个工作表。我想要一个通用宏,它从与按钮相同的行号复制数据,而不是B2在代码中如下所述。

目前这段代码运行良好;按钮文本已更新并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
4

1 回答 1

2

未经测试,但可能会帮助你......

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
于 2012-07-24T06:34:34.113 回答