VBA for Excel - 删除行时出现问题

发布于 2024-11-27 03:22:07 字数 908 浏览 0 评论 0原文

我试图让 VBA 删除由两个变量定义的一系列行。当例程到达显示 Range(Cells(FirstDeletedLine, 0), Cells(LastDeletedLine, 0)).Select 的行时,我收到一条错误消息。

以下是完整代码:

FirstDeletedLine = Worksheets("Data Export").Cells(95, 2).Value
LastDeletedLine = Worksheets("Data Export").Cells(96, 2).Value
LastCopiedCell = Application.WorksheetFunction.VLookup("Copy to", Range("A:B"), 2, 0)
'
    Sheets("Data Export").Visible = True
    Sheets("Data Export").Select
    Range(Cells(FirstDeletedLine, 0), Cells(LastDeletedLine, 0)).Select
    Selection.Delete Shift:=xlUp
    Range("D6:LastCopiedCell").Select
    Selection.Copy
    Windows("DFCB LATAM DECK.xlsx").Activate
    Sheets("REVENUE - QTD v. BUD").Select
    Range("B14").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B13").Select
End Sub

我非常感谢您的帮助。谢谢!

I'm trying to get VBA to delete a range of rows that are defined by two variables. I get an error message when the routine reaches the line that says Range(Cells(FirstDeletedLine, 0), Cells(LastDeletedLine, 0)).Select.

Below is the whole code:

FirstDeletedLine = Worksheets("Data Export").Cells(95, 2).Value
LastDeletedLine = Worksheets("Data Export").Cells(96, 2).Value
LastCopiedCell = Application.WorksheetFunction.VLookup("Copy to", Range("A:B"), 2, 0)
'
    Sheets("Data Export").Visible = True
    Sheets("Data Export").Select
    Range(Cells(FirstDeletedLine, 0), Cells(LastDeletedLine, 0)).Select
    Selection.Delete Shift:=xlUp
    Range("D6:LastCopiedCell").Select
    Selection.Copy
    Windows("DFCB LATAM DECK.xlsx").Activate
    Sheets("REVENUE - QTD v. BUD").Select
    Range("B14").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("B13").Select
End Sub

I deeply appreciate your help. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2024-12-04 03:22:07

我认为你需要将其设置为 Range(Cells(FirstDeletedLine, 1) (而不是 0)。Cells 是基于 1 的,没有列 0。

I think you need to make it Range(Cells(FirstDeletedLine, 1) (instead of 0). Cells is 1 based, there is no column 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文