Macro to delete certain value

P

Paul

I have the following data in an xls:

1
2
3
4
5
0
0
0
0
0

I need to create a macro to delete all the rows that
contain 0.
However, the start position of 0 can vary (i.e. in one
instance it could start at A5, but the next instance might
start at A10).

Can anyone help?

Thanks,
Paul
 
F

Frank Kabel

Hi
try the following macro
Sub delete_rows()
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
For RowNdx = LastRow To 1 Step -1
with Cells(RowNdx, "A")
if .value = 0 then
Rows(RowNdx).Delete
End If
end with
Next RowNdx
Application.ScreenUpdating = True
End Sub
 
P

Paul

Frank,

I have tried this, but it hasn't done anything?!

Any ideas?

Your helps appreciated.

Paul
 
F

Frank Kabel

Hi Paul
if your values are in column A and are real numbers this should work.
did you get an error or hwat happens after starting this macro?
 
F

Frank Kabel

Hi Paul
could you email me your file. The code should only delete all rows with
a zero in column A.
email: frank[dot]kabel[at]freenet[dot]de
 
Top