Reputation: 3168
I'm looping row inside sheet and I want to find string inside some text:
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
lrk = wsK.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lr --looping list
look_name = UCase(ws.Range("E" & i).Value)
For j = 2 To lrk --loop patern value
look_text = UCase(wsK.Range("A" & j).Value)
If look_name Like "*look_text*" Then --if found
ws.Range("AB" & i) = wsK.Range("B" & j).Value --to do
Exit For
End If
Next j
Next i
I think something wrong I did with "*look_text*"
If look_name = "New city"
and look_text = "city"
, it's not going into IF.
Upvotes: 0
Views: 67
Reputation: 33672
Another option, since you are adding wild-card *
in the beginning and the end of your String
, is to use Instr
Function.
If Instr(look_name, look_text) > 0 Then
Edit 1: with text provided from PO
If InStr("abcabc testa abcbc", "test") > 0 Then
MsgBox "Instr Works"
End If
Upvotes: 3
Reputation: 3168
I managed to solve the issue by changing
If look_name Like "*look_text*" Then
to
If look_name Like "*" & look_text & "*" Then
Upvotes: 1