考虑到这一点,我可能需要一些VBA,但如果我能避免它,那就太好了。
我有以下excel表(见图)
目标:我想在列B中列出使用A列完成C列语法搜索的结果。在我的情况下,列B将为yes,tata,well
,因为列A具有I2010等。
我尝试使用vlookup
,但vlookup
的目标是特定字符串,例如I2010
或IS-IPI
,而不是其中的一部分。
欢迎任何建议。
由于
答案 0 :(得分:0)
在B1中,输入:
=IF(FIND(C1,$A$1)>0,D1,"")
然后向下拖动。这将根据您在工作表中的确切要求而改变。需要进一步澄清,以便根据您的需求量身定制,但这至少为您提供了一个起点。
答案 1 :(得分:0)
使用
andylookup(A1, C1:D4, "Not Found!")
代码:
Function andyLookup(strInput As String, rngTable As Range, defaultvalue As String) As String
Dim strArray() As String
Dim i As Integer
Dim strOut As String
Dim temp1 As Variant
strArray = Split(strInput, ",")
For i = 0 To UBound(strArray)
temp1 = Application.VLookup(strArray(i), rngTable, 2, 0)
'if not found, apply default value
If IsError(temp1) Then
strOut = strOut & defaultvalue & ","
Else
strOut = strOut & temp1 & ","
End If
Next
'remove trailing comma
strOut = Left(strOut, Len(strOut) - 1)
andyLookup = strOut
End Function
结果
yes,toto,tata,well
答案 2 :(得分:0)
或使用VBA的Find
Sub Main()
MsgBox LookupStr(Range("A1"), Range("B1:B4"))
End Sub
Function LookupStr(rng1 As Range, rng2 As Range) As String
Dim rng3 As Range
Dim rng4 As Range
For Each rng3 In rng2
Set rng4 = rng1.Find(rng3.Value, , xlFormulas, xlPart)
If Not rng4 Is Nothing Then LookupStr = LookupStr & rng3.Offset(0, 1) & vbNewLine
Next
End Function