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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

hsk

Well-known Member
Joined
Oct 19, 2006
Messages
567
have u tried "Left" function ??

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

.........
 

DougStroud

Well-known Member
Joined
Aug 16, 2005
Messages
2,968
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
 

gaj104

Well-known Member
Joined
Nov 9, 2002
Messages
864
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
 

Forum statistics

Threads
1,181,412
Messages
5,929,784
Members
436,692
Latest member
ModestMuse

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