gpt4 book ai didi

excel - msgBox 未显示成功结果

转载 作者:行者123 更新时间:2023-12-04 20:42:47 24 4
gpt4 key购买 nike

我有以下设置来复制列表并粘贴到工作表(数据)。我希望它在成功时显示一条消息,告诉我它是从哪一行开始粘贴的。但是,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:) 尝试调试此问题的一种方法是删除/注释掉“On Error GoTo”,然后运行代码。这应该告诉你哪一行产生了错误。
也就是说,我怀疑你想要 current = ActiveCell.Index成为 current = ActiveCell.Address .

关于excel - msgBox 未显示成功结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28934893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com