macro

  • Thread starter Thread starter C3
  • Start date Start date
C

C3

HI!

How to make a macro who will find some value (etc. 0) in a specific column
(etc. column B), and erase entire row.

Thanks.
 
Hi
try the following macro
Sub delete_rows()
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).row
For RowNdx = LastRow To 1 Step -1
with Cells(RowNdx, "B")
if .value = 0 then
Rows(RowNdx).Delete
End If
end with
Next RowNdx
Application.ScreenUpdating = True
End Sub
 
something like this to check column A
Sub delzeros()
For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If Cells(i, 1) = 0 Then Rows(i).Delete
Next
End Sub
 
If there is just one or no occurrence, use the Find method. Add FindNext if
multiple occurrences.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Keep in mind that depending upon what values are allowed in your spreadsheet, you might need to watch out for empty cells and cells with the value of FALSE. I believe that these will also evaluate to 0. If necessary you can use the IsEmpty function to test for empty cells. Also, you can use the Str function to convert your cell to a string. This should help to identify cells that are FALSE

Art
 

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