Macro to delete rows

  • Thread starter Thread starter Michelle
  • Start date Start date
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
 
Michelle,
This is asked so often. Did you try the archives or Ron deBruin's google
addin
 
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
 
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
(e-mail address removed)
 
Back
Top