VBA for Excel - 删除行的问题

时间:2011-07-31 21:23:13

标签: vba excel-vba delete-row 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

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

1 个答案:

答案 0 :(得分:3)

我认为您需要将其设为Range(Cells(FirstDeletedLine, 1)(而不是0)。单元格基于1,没有第0列。