Gus
Gus

Reputation: 1

VBA for Excel - problem deleting rows

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!

Upvotes: 0

Views: 466

Answers (1)

iDevlop
iDevlop

Reputation: 25252

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

Upvotes: 3

Related Questions