Delete Row Based on Word in Cell

cjvenables

Board Regular
Joined
Aug 2, 2011
Messages
65
Hello,

I'm trying to search each cell in column C and see if contains OPEN, CLOSED, or PROCESSED. If they do not contain any 1 of those 3 words, I want to delete the entire row.

I have been unsuccessful with my code so far, hopefully you guys can provide some guidance.

Thanks so much,

Code:
Sub Delete()

Application.ScreenUpdating = False
Dim rng As Range
Dim colwords As Variant

colwords = Array("OPEN", "CLOSED", "PROCESSED")

For Each rng In Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
        If rng.Value <> colwords Then EntireRow.Delete
Next rng

Application.ScreenUpdating = True
MsgBox "Your Macro is Complete!", vbOKOnly, "Macro Status"

End Sub
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub Delete()

Application.ScreenUpdating = False
Dim rng As Range

colwords = Array("OPEN", "CLOSED", "PROCESSED")

For Each rng In Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
        If IsError(Application.Match(rng.Value, Array("OPEN", "CLOSED", "PROCESSED"), 0)) Then EntireRow.Delete
Next rng

Application.ScreenUpdating = True
MsgBox "Your Macro is Complete!", vbOKOnly, "Macro Status"

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,971
Messages
5,599,109
Members
414,289
Latest member
sonintebil

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
Top