ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditional row delete using macr (https://www.excelbanter.com/excel-programming/314579-conditional-row-delete-using-macr.html)

Robert

Conditional row delete using macr
 
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.............

daverico

Conditional row delete using macr
 

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

--
daveric
-----------------------------------------------------------------------
daverico's Profile: http://www.excelforum.com/member.php...fo&userid=1566
View this thread: http://www.excelforum.com/showthread.php?threadid=27199


Frank Kabel

Conditional row delete using macr
 
Hi
you have to work from the bottom up to the top.

"Robert" wrote:

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.............



All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com