excel - 在单元格文本中查找字符串(VB)
问题描述
我在工作表内循环行,我想在一些文本中找到字符串:
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
我认为我做错了什么"*look_text*"
如果look_name = "New city"
和look_text = "city"
,它不会进入 IF。
解决方案
另一种选择是使用*
Function .String
Instr
If Instr(look_name, look_text) > 0 Then
编辑 1:使用 PO 提供的文本
If InStr("abcabc testa abcbc", "test") > 0 Then
MsgBox "Instr Works"
End If