msgBox 未显示成功结果
msgBox is not showing up on successful result
我有以下设置来复制列表并粘贴到 sheet(data)。我希望它在成功时显示一条消息,告诉我它从哪一行开始粘贴。但是,显示的是 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:) 尝试调试此问题的一种方法是 remove/comment-out "On Error GoTo",然后 运行 代码。那应该告诉你哪一行产生了错误。
也就是说,我怀疑您希望 current = ActiveCell.Index
成为 current = ActiveCell.Address
.
我有以下设置来复制列表并粘贴到 sheet(data)。我希望它在成功时显示一条消息,告诉我它从哪一行开始粘贴。但是,显示的是 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:) 尝试调试此问题的一种方法是 remove/comment-out "On Error GoTo",然后 运行 代码。那应该告诉你哪一行产生了错误。
也就是说,我怀疑您希望 current = ActiveCell.Index
成为 current = ActiveCell.Address
.