這裏有一個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