Deleting Rows Based on Column Cell Content

dantb

Active Member
Joined
Mar 20, 2002
Messages
358
Hello all:, I have found a lot of vb on deleting rows if it contains a certain value or word, but I can not find out how to delete a row if it does not have a certain value. My workbook in column ( C ) contains the word ( PROD: ) and I am looking for a way that if that word is not found in Column C, Delete the Entire row. My Data ends on row 800 also. Thanks Dan
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
An example of a VBA IF statement that would fit is:

Code:
If Cell.Value <> "PROD:" Then
Cell.EntireRow.Delete
End IF
 
Upvote 0
Here is an example I tested with some VBA:
Book1
ABCD
11Prod:
22
33Prod:
44
55Prod:
66Prod:
77Prod:
88
99Prod:
1010Prod:
Sheet1


Disregard the cells with &nsbp, not sure why that shows up.

Here is the code:<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DeleteRows()<SPAN style="color:#00007F">Dim</SPAN> WorkRange<SPAN style="color:#00007F">As</SPAN> Range<SPAN style="color:#00007F">Set</SPAN> WorkRange = Range("C1:C" & Range("C65536").End(xlUp).Row)<SPAN style="color:#00007F">For</SPAN><SPAN style="color:#00007F">Each</SPAN> Cell<SPAN style="color:#00007F">In</SPAN> WorkRange
    <SPAN style="color:#00007F">If</SPAN> UCase(Cell.Value)<> "PROD:"<SPAN style="color:#00007F">Then</SPAN>
        Cell.EntireRow.Delete
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Next</SPAN> Cell<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
This is what I have been trying but it will Lock Excel up, Do not run code. I just dont know what is wrong with the statement. Thanks Dan


LastRow = Range("C65536").End(xlUp).Row
For i = 1 To LastRow
If Range("C" & i) = "PROD:" Then
Rows(i).Delete shift = xlShiftUp
i = i - 1
End If
Next i
 
Upvote 0
Thanks Banker that is what I was looking for, been driving me nuts. Thanks again Dan
 
Upvote 0

Forum statistics

Threads
1,196,322
Messages
6,014,638
Members
441,833
Latest member
Rangerreeve

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