msgBox没有显示成功结果

时间:2015-03-09 03:39:14

标签: excel excel-vba msgbox vba

我有以下设置来复制列表并粘贴到工作表(数据)。我希望它在成功时显示一条消息,告诉我它开始粘贴的哪一行。但是,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

1 个答案:

答案 0 :(得分:1)

欢迎使用SO :)尝试调试此方法的一种方法是删除/注释掉“On Error GoTo”,然后运行代码。这应该显示哪一行产生错误。 也就是说,我怀疑你希望current = ActiveCell.Index成为current = ActiveCell.Address