Macro to delete rows

M

Michelle

I am trying to find a Macro that:

Deletes an entire row if a certain cell is blank. For
example: If column E7 if blank or zero, I would like to
delete the entire row 7, same for if E50 is blank or zero,
then delete row 50, and so on.

Thanks for the help.

Michelle
 
D

Don Guillett

Michelle,
This is asked so often. Did you try the archives or Ron deBruin's google
addin
 
I

icestationzbra

Option Explicit

Sub DeleteRows()

Dim i As Integer
Dim n As Integer

With Sheet1

n = .Range("e1").CurrentRegion.Rows.Count

For i = 2 To n

If .Range("e" & i).Value = 0 Or .Range("e" & i).Value = "" Then

Range("e" & i).EntireRow.Delete

Else

GoTo None

End If

Next i

End With

None:
MsgBox "No rows to delete!"

End Su
 
N

Nick Hodge

I suspect you would need to change the line

For i = 2 To n

to

For i = n to 2 step -1

When deleting rows if you don't go 'backwards' you will skip rows as they
are deleted and moved up

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]
 
Top