Delete rows with 0 in target cell

S

Shawn

Below is a handy code I have used to serch a range and delete all cells with
a 0. I need to modify this slightly so it will not only delete the cells
with 0, but all the cells with 0 along with the four cells to the left of
that cell. For example, if cell F5 has a 0 in it, it will delete cells A5:F5.

Dim xRange As Range
Dim xCell As Range

For Each xCell In Sheets("SDII").Range("F2:F34")
If xCell.Value = 0 Then
If xRange Is Nothing Then
Set xRange = xCell
Else
Set xRange = Union(xRange, xCell)
End If
End If
Next xCell
xRange.Delete Shift:=xlUp
 
P

Patrick Molloy

replace
xRange.Delete Shift:=xlUp
by
xRange.offset(,-4).resize(,5).Delete Shift:=xlUp

shouldn't this be INSIDE your FOR...NEXT loop?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top