delete rows based on value in a column cell that is > or equal to 0

ToniB

New Member
I need to create a macro to delete rows if the value of a cell in column J is > or = to zero. The worksheet will vary in length, but will always use columns C through J. I know this is easy, but I can't get it right. Any help is greatly appreciated!
 

Michael M

Well-known Member
MAybe this

Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
For r = lr To 2 Step -1
  If Cells(r, "J") >= 0 Then Rows(r).Delete
Next r
End Sub
 

ToniB

New Member
Thank you Michael!

I also need to have it omit the header and start with row 6. What I did below did not work.


Sub DeleteRow()


Dim FirstRow As Long
FirstRow = 6
Dim lr As Long, r As Long
lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
For r = lr To 2 Step -1


If Cells(r, "J") >= 0 Then Rows(r).Delete


Next r


End Sub
 

Michael M

Well-known Member
Change this line

Code:
For r = lr To 2 Step -1
To

Code:
For r = lr To [color=red][b]6[/b][/color] Step -1
 

ToniB

New Member
Thank you Michael - that worked perfectly! I have been messing with this all day - I appreciate your quick solution!
 

Some videos you may like

This Week's Hot Topics

Top