vba wildcard search on cell

雨燕双飞 提交于 2019-12-01 08:09:08

问题


I'm trying to find something with a wild card search in a cell value. If the value in sheet("FC")Range("I2:I" & LastRowC) - match with the Sheets("Instr"),Range("A130:A190"). means sheet Instr match if few characters match with the other range mentioned above then do something code.

eg in sheet Instr above range a cell value is "Ajith" and In sheet FC above mentioned range one of the cell value is "Aji" the code should identify it.

All the below steps are okay for me except the wild card search through the loop range , please go through the code and range (rename the sheets if necessary as below) and provide an update.

Sub Exception()

Dim mfc As Worksheet
Dim mfp As Worksheet
Dim mfo As Worksheet
Dim instr As Worksheet

Set mfc = Sheets("FC")
Set mfp = Sheets("FP")
Set mfo = Sheets("OSLR")
Set inst = Sheets("Instr")

Dim irng As Range
Dim icel As Range

Set irng = inst.Range("A130:A190")

Dim LastRowC As Long
LastRowC = mfc.Cells(Rows.Count, 1).End(xlUp).Row

Dim fcphr As Range
Dim fcphc As Range

Set fcphr = mfc.Range("I2:I" & LastRowC)

For Each icel In irng.Rows
For Each fcphc In fcphr.Rows

If icel.Value = "" Then
Exit For
End If
If fcphc.Value = "" Then
Exit For
End If

If fcphc.Value = icel.Value Then

    msgbox fcphc
    msgbox icel

    '***(i need a wild card search for the above step)***

End If

Next fcphc
Next icel


End Sub

回答1:


You could use the Like operator. For example:

If fcphc.Value Like "*" & icel.Value & "*" Then

If you wanted the comparison to work both ways:

If _
    fcphc.Value Like "*" & icel.Value & "*" Or _
    icel.Value Like "*" & fcphc.Value & "*" _
Then


来源:https://stackoverflow.com/questions/48030637/vba-wildcard-search-on-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!