Macro to delete certain value

  • Thread starter Thread starter Paul
  • Start date Start date
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
 
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
 
Frank,

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

Any ideas?

Your helps appreciated.

Paul
 
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?
 
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
 

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