【发布时间】:2015-03-09 03:39:14
【问题描述】:
我有以下设置来复制列表并粘贴到工作表(数据)。我希望它在成功时显示一条消息,告诉我它是从哪一行开始粘贴的。但是,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
【问题讨论】:
-
范围对象没有
Index property or method。这可能会导致@Pillgram 在他的帖子中提到的错误。您可以尝试ActiveCell.Row来获取您粘贴值的行。 -
我使用 .Row 而不是 .address 但两者都有效。谢谢。