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

ToniB

New Member
Joined
Jan 5, 2019
Messages
6
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!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
Thank you Michael - that worked perfectly! I have been messing with this all day - I appreciate your quick solution!
 
Upvote 0

Forum statistics

Threads
1,212,928
Messages
6,110,737
Members
448,295
Latest member
Uzair Tahir Khan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top