我需要在excel中创建一个函数(或宏,这更容易),如果选择CONTAINS“Specified Text1”或者如果它包含“Specified Text2”则返回“Text1”然后返回“Text2”并且如果它包含“Specified Text3”然后返回值“Text3”。
答案 0 :(得分:2)
在我的评论中提出进一步的澄清我想问你的问题:
如果我说得对,你有“abc”,def“和”ghi“在”hstdefhrk“中搜索,同时输出”123“,”456“和”789“作为输出=>你想获得“456”......这是对的吗?
通过公式得到这个:
'case sensitive
=INDEX({"";"OutputText1";"OutputText2";"OutputText3"},MAX(ROW($1:$4)*ISNUMBER(FIND({"";"SearchText1";"SearchText2";"SearchText3"},A1))))
'not case sensitive
=INDEX({"";"OutputText1";"OutputText2";"OutputText3"},MAX(ROW($1:$4)*ISNUMBER(SEARCH({"";"SearchText1";"SearchText2";"SearchText3"},A1))))
这是一个数组公式,必须使用 Ctrl + Shift + Enter 确认。
将其作为UDF进行尝试:(不区分大小写)
Public Function multiSearch(sourceStr As String, srcMatrix As Variant, dstMatrix As Variant, Optional caseSen As Boolean) As String
Dim runner As Variant, i As Long
For Each runner In srcMatrix
If InStr(1, sourceStr, runner, caseSen + 1) Then Exit For
i = i + 1
Next
For Each runner In dstMatrix
If i = 0 Then
multiSearch = runner
Exit For
Else
i = i - 1
End If
Next
End Function
并像LOOKUP
=multiSearch([striong to search in],[array of strings to search for],[array of strings to output],[1/true for case sensitive])
=multiSearch(A1,{"SearchText1";"SearchText2";"SearchText3"},{"OutputText1";"OutputText2";"OutputText3"}) 'not case sensitive
=multiSearch(A1,D1:D6,E1:E6,1) 'case sensitive
答案 1 :(得分:1)
尝试,
$(function() {
$('#myButton').on('click', function() {
$('#myDiv').addClass('transition-class');
});
});
答案 2 :(得分:0)
我将假设实际字符串不是“指定文本”和一些数字。它们实际上是独立的字符串。
您可以使用嵌套的if语句:
=IF(NOT(ISERROR(SEARCH("Specified Text1",A1))),"Text1",IF(NOT(ISERROR(SEARCH("Specified Text2",A1))),"Text2",IF(NOT(ISERROR(SEARCH("Specified Text3",A1))),"Text3","")))