VBA for Excel - 删除行时出现问题
我试图让 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你需要将其设置为
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.