Cut out rows based on wildcard criteria

amitcohen

Board Regular
Joined
Jan 14, 2010
Messages
118
Hi

This code loop through list of criteria and move(cut) any row with a match.

How can I use a 'wild card' here?

Code:
    Dim TheRange As Range
    Dim TheCell As Range
    Set TheRange = Range("A1:E3500", Range("A65536").End(xlUp))
    Dim R      As Long
    
    
'Start check list by criteria
For i = 1 To 5 Step 1

    For Each TheCell In TheRange.Cells
     If TheCell = Sheets("Criteria").Range("A" & i).Value Then
                    R = TheCell.Row
            Range(Cells(R, 1), Cells(R, 5)).Cut _
Destination:=Sheets("RemovedData").Range("A65536").End(xlUp).Offset(1, 0)
        End If
    Next TheCell

Next i


Thanks for the help,

Amit.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Maybe like this

Code:
If TheCell.Value Like "*" & Sheets("Criteria").Range("A" & i).Value & "*" Then
 
Upvote 0
Thanks VoG
This is great!! :)

If I may ask one more Q here..
(Or should I start new thread)

How to re-run the macro so it will check the criteria again, this time on column B ?


Amit
 
Upvote 0
Try

Code:
If TheCell.Value Like "*" & Sheets("Criteria").Range("A" & i).Value & "*" _
    Or TheCell.Value Like "*" & Sheets("Criteria").Range("B" & i).Value & "*" Then
 
Upvote 0

Forum statistics

Threads
1,215,416
Messages
6,124,774
Members
449,187
Latest member
hermansoa

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