在单元格上的vba通配符搜索 [英] vba wildcard search on cell
问题描述
我正在尝试使用通配符搜索在单元格值中找到某些内容.如果sheet("FC")Range("I2:I"& LastRowC)中的值与Sheets("Instr"),Range("A130:A190")匹配.表示工作表Instr匹配,如果很少有字符与上述其他范围匹配,则执行一些代码.
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.
例如,在表格Instr以上范围中,单元格值为"Ajith",而在表格FC以上中提到的范围中,单元格值之一为"Aji",代码应对此进行标识.
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
推荐答案
您可以使用Like
运算符.例如:
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
这篇关于在单元格上的vba通配符搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!