Deleting Data based on Criteria and Wild Cards

Karen Schomer

New Member
Joined
Feb 4, 2005
Messages
1
How can I delete rows of data using criteria/wildcards?

Example: Data is:
Coke Cola / Alabama
Coke Cola - New Jersey
7-Up / California
Coke Cola (Washington)
7-Up - New York
Root Beer / Florida

Result: Delete all the Coke Cola*
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Welcome to the Board!

You could sort by that column and delete the records you want, or use Data, Autofilter to show only the relevant rows, then delete them. Hope that helps!
 
Upvote 0
Hi Karen, welcome to the board.

If the values you've shown in your example are all in one column then the autofilter won't do you much good. (Will be great if they're not in one column...) but if they are, then maybe something along these lines is in order. (Assumes they are in column A...)

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DeleteCokeColaRows()
<SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
x = Cells(65536, 1).End(xlUp).Row
<SPAN style="color:#00007F">For</SPAN> i = x <SPAN style="color:#00007F">To</SPAN> 1 <SPAN style="color:#00007F">Step</SPAN> -1
    <SPAN style="color:#00007F">If</SPAN> InStr(Cells(i, 1), "Coke Cola") <SPAN style="color:#00007F">Then</SPAN> Cells(i, 1).Rows.EntireRow.Delete
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope it helps,
Dan
 
Upvote 0

Forum statistics

Threads
1,203,108
Messages
6,053,561
Members
444,673
Latest member
Jagadeshrao

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