VBA - Delete Rows based on cell value

Jason Micahel

New Member
Joined
Jan 18, 2005
Messages
4
I have wrote code to delete a row if the value equals something. Sample Code Below:
lRow = Cells(65536, 1).End(xlUp).Row
For z = lRow To 1 Step -1
If Cells(z, 16).Value = "OP" Then Rows(z).Delete
Next z

So in this code I am telling it to go up one row at a time, look at column 16 to see if "OP" is in the column if it is then delete the row. and repeat the next row.
Can someone please help me out with this, I am trying to write something to delete rows if the cell value is not equal to something.. And if it is possible I want to say If Cells(z, 16).Value <1 Then Rows(z).Delete
but this give me an error..

So basically I need your help with a code for not equal to a cell value then delete rows, and if cell value if less than "X" then delete rows..

Thanks in advance for your time and thoughts on this.... :oops:
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Upvote 0
That makes sense, thanks..
Stupid question time for you..

to put this in my code to say is a cell is not equal to X then ???

lRow = Cells(65536, 1).End(xlUp).Row
For z = lRow To 1 Step -1
If Cells(z, 16).Value <> 1 Then Rows(z).Delete
Next z

So this would be what I need if I am trying to delete anything in column N(16) that is not equal to 1.
 
Upvote 0

Forum statistics

Threads
1,203,607
Messages
6,056,284
Members
444,855
Latest member
archadiel

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