这里有一个VBA用户定义函数可以用返回的第一个项目在包含您的搜索文本的列表中,只需在VBA编辑器窗口中的新模块中输入此代码(Alt + F11以打开VBA编辑器)
Public Function FIRSTWITHIN(lookfor As String, lookin As Variant) As String
Dim tmparray() As Variant
Dim firstmatch As String
firstmatch = "No matching URL found."
'Feeds lookin into temporary array. Error Handler handles case where lookin is a range.
'This allows use of function in array formula.
On Error GoTo ErrHandler
tmparray = lookin
'Looks through array column by column for match. Returns first match found.
For j = 1 To UBound(tmparray, 2)
For i = 1 To UBound(tmparray, 1)
If InStr(tmparray(i, j), lookfor) > 0 Then
firstmatch = tmparray(i, j)
Exit For
End If
Next i
If firstmatch <> "No matching URL found." Then
Exit For
End If
Next j
FIRSTWITHIN = firstmatch
Exit Function
ErrHandler:
tmparray = lookin.Value
Resume Next
End Function
然后,您可以使用的功能如下:
=FIRSTWITHIN("example-text",A2:A20)
其中A2:A20是要通过搜索URL列表。
谢谢jmax。只是试过,并不能让它去..这个公式工作在一个列表?也如何让它返回包含正确的搜索片段的网址? – Edward
这是[GoogleDocs上的示例](https://docs.google.com/spreadsheet/ccc?key=0Avv4SM5QSNYtdHlUU3E0REFMMVdjVFpQeUkwOVVZRWc&hl=en_GB)(与Excel几乎相同) – JMax
哦,我明白了,再次感谢。是的,我不认为我解释得很好,我会有另一个刺:说我有一长串的网址我想看看是否在网址中出现“example-text”,那么如果是这样的话forumla输出itslef是包含“示例文本”的url ..是可行的吗?谢谢。爱德华 – Edward