Conditional row delete using macr

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The macro below deletes alternate rows instead of all rows with Zero. I do not
know VBA. What is wrong.

Application.Goto Reference:="col"
For Each cell_in_loop In Range("col")
If cell_in_loop.Value=0 Then With cell_in_loop.EntireRow.Delete
End With
End If
Next
ActiveWorkbook.SaveAs Filename:=C\Data\Sales.............
 
This is not going to work because you are deleting one row and then th
loop goes onto the next one (when it should stay at the same row an
question it again).

More appropriate might be (substitute "A" with the column that has th
values in):
dim y as long
dim x as long
y = range("A65536").end(xlup).row
x = 1
while x < y +1
If range("A" & x).Value=0 Then With range("A" & x).EntireRow.Delete
End With
y = y - 1
else
x = x + 1
End If
wend
ActiveWorkbook.SaveAs Filename:=C\Data\Sales.............

This should work
 

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

Back
Top