Wildcard operators to use with LIKE

  • Thread starter Thread starter LuisE
  • Start date Start date
L

LuisE

I’m using LIKE to determine if a cell contains certain text, but I don’t know
how to use the wildcard characters or how to structure a pattern to make the
search effective.
I want to find any cell with the text “traf10†in it not necessarily being
that string the only content of the cell.

If Cell2Srch.Value Like "traf10" And Not Cell2Srch.Value Like "traf106" Then
Cells(Cell2Srch.Row, 1).Value = "Yes"
End If

Thanks in advance
 
Hi,

Try this alternative to like

If InStr(cell2srch, "traf10") And Not InStr(cell2srch, "traf106") Then
Cells(cell2srch.Row, 1).Value = "Yes"

Mike
 
I think the wild cards would make it look like this:

If Cell2Srch.Value Like "*traf10*" And Not Cell2Srch.Value Like "*traf106*"
Then
Cells(Cell2Srch.Row, 1).Value = "Yes"
End If

Tom
 
This should do the same thing PROVIDED there is always at least one
character following the 'traf10' characters...

If Cell2Srch.Value Like "*traf10[!6]*" Then
 
I guess this version will work properly even if there is no character
following the 'traf10' characters...

If Cell2Srch.Value & " " Like "*traf10[!6]*" Then

--
Rick (MVP - Excel)


Rick Rothstein said:
This should do the same thing PROVIDED there is always at least one
character following the 'traf10' characters...

If Cell2Srch.Value Like "*traf10[!6]*" Then

--
Rick (MVP - Excel)


TomPl said:
I think the wild cards would make it look like this:

If Cell2Srch.Value Like "*traf10*" And Not Cell2Srch.Value Like
"*traf106*"
Then
Cells(Cell2Srch.Row, 1).Value = "Yes"
End If

Tom
 
Back
Top