Conditions in a macro

  • Thread starter Thread starter Damon
  • Start date Start date
D

Damon

Hey there,

I am trying to have my marco delete all rows with a value equal to or less
then 0 (in a particular field). Any help would be great.

Thanks,
 
Sort them first (programmatically if you wish - do a macro record to
see how), then do a find for zero, then delete all rows below.
 
Hi Damon.
Try:

Sub Cancellariga()
Dim R As Long
Dim LR As Long
With ActiveSheet
LR = .Cells(Rows.Count, 1).End(xlUp).Row
For R = LR To 1 Step -1
If .Cells(R, 1).Value = 0 Then
.Cells(R, 1).EntireRow.Delete
End If
Next
End With
End Sub

Regards
Eliano
 
Sub DeleteRows()
Dim iLastRow As Long
Dim I As Long
iLastRow = Cells(Rows.Count, "C").End(xlUp).Row
For I = iLastRow To 1 Step -1
If Cells(I, "C").Value <= 0 Then
Rows(I).Delete
End If
Next I
End Sub

Edit the "C" to suit.


Gord Dibben MS Excel MVP
 
Sorry Damon, ut i forget the minus sign.

If .Cells(R, 1).Value = 0 Then

is intended as:

If .Cells(R, 1).Value <= 0 Then

Eliano
 
James,

I think that will work. Thank you very much. I will try that right now.
 

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