Thread: delete row
View Single Post
 
Old 10-04-2012, 11:52 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For Z = lastRow to 2 Step -1
  If Cells(Z, 4) = "" Then Cells(Z, 4).EntireRow.Delete
Next Z
The problem with a forward-working For .. Next loop when you're deleting items is that, upon deletion, the next item moves into the deleted item's position and doesn't get tested on the next iteration, because it's no longer at its former location.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote