msgBox没有显示成功的结果

我有以下设置复制一个列表并粘贴到工作表(数据)。 我希望它在成功时显示一条消息,告诉我它开始粘贴的是哪一行。 但是,errmsg会显示。

提前致谢

Dim current As String current = ActiveCell.Index MsgBox current & "pasted there" Exit Sub errmsg: MsgBox "failed to copy." End Sub 

完整的代码

 Sub move() Range("A3:B3").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("K3").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("F3:I3").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Range("F3").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft Range("A3:G3").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy On Error GoTo errmsg Sheets("data").Select Range("A1").Select Selection.End(xlDown).Offset(1, 0).Select Selection.PasteSpecial Paste:=xlPasteValues Dim current As String current = ActiveCell.Index MsgBox current & "pasted there" Exit Sub errmsg: MsgBox "failed to copy." End Sub 

欢迎来到SO :)试图debugging的一种方法是删除/注释掉“On Error GoTo”,然后运行代码。 这应该告诉你哪一行正在产生错误。 这就是说,我怀疑你想要current = ActiveCell.Indexcurrent = ActiveCell.Address