Add wildcard* character to Term in Code to change value

DougStroud

Well-known Member
Joined
Aug 16, 2005
Messages
2,968
The following line of code searches for the term "Boot", but I want it to find any instance of "Boot", ie. "Boot", "Bootw", or "Booty".
Placing the standard * after the term does not work...
If (Cells(i, "F") = "Hat" Or Cells(i, "F") = "Shoe" Or Cells(i, "G") = "Boot*") And Cells(i, _
"M").NumberFormat = "0.000" Then

or

If (Cells(i, "F") = "Hat" Or Cells(i, "F") = "Shoe" Or Cells(i, "G") = "Boot" & "*") And Cells(i, _
"M").NumberFormat = "0.000" Then

Does not work....
 

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
have u tried "Left" function ??

If Left(Cells(11, 3).Value, 3) = "ABC" Then

.........
 
Upvote 0
Hello Hsk-
I did try that earlier, but could not get the syntax correct for it to work.
Here is my original line- can you provide an example w/ the "Left" function included?

Code:
If (Cells(i, "F") = "Hat" Or Cells(i, "F") = "Shoe" Or Cells(i, "G") = "Boot") And Cells(i, _
    "M").NumberFormat = "0.000" Then
 
Upvote 0
Use the find function as a better test. I also cleaned up your code and created a separate function to test the cell

Hope it helps

Code:
Sub LookFor()


If Cells(i, "M").NumberFormat = "0.000" Then

    If Finder(Cells(i, "F")) = True Then
    
    'put code here where conditons are met
    
    End If

End If

End Sub

Function Finder(rng As Range) As Boolean

Dim findValues As Variant
Dim j As Long

findValues = Array("Hat", "Shoe", "Boot")

For j = LBound(findValues) To UBound(findValues)
    
    If Not (rng.Find(findValues(j)) Is Nothing) Then
        
        Finder = True
        Exit Function
    
    End If

Next j

Finder = False

End Function
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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