Matt Ridge
Matt Ridge

Reputation: 3651

Delete a row starting at a specific row, Excel VBA

wsIMP.Columns(4).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

The code will delete everything in D that is an empty cell, which I want, is there a way to add more into this code to start at row 6?

I though it would be simple like .Rows(6).Columns(4), but it doesn't seem to work. Anyone got an idea how to make this work correctly?

Upvotes: 0

Views: 1744

Answers (3)

Scott Holtzman
Scott Holtzman

Reputation: 27249

dim lastrow as Long

With wsIMP
    lastrow = .Range("D" & .rows.count).end(xlup).Row 
    .Range("D6:D" & lastrow).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With

If you wish to write in one line, as in your comment, do this.

wsIMP.Range("D6:D" & wsIMP.Range("D" & wsIMP.Rows.Count).End(xlUp).Row).SpecialCells ...

But if you ask me, that is much harder to read.

Upvotes: 1

GeneralMike
GeneralMike

Reputation: 3001

Hm, I haven't worked with coding in excel too much, but I've done quite a bit in Access, and I feel like I remember using either .Colums(6)(4) or .columns(6,4) to do this, maybe give each of those a quick shot. If neither of those work, I'm afraid I can't help.

Upvotes: 0

danielpiestrak
danielpiestrak

Reputation: 5439

Try This:

wsIMP.Range("D6","D" & wsIMP.rows.count).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Upvotes: 1

Related Questions