Поиск строки предложения
Вы можете получить длинную формулу для нескольких предложений, но я не думаю, что она решит вашу задачу.Поэтому я разработал пользовательскую функцию (UDF).Скопируйте код в стандартный модуль.
Function SSS(ByVal SearchString As String, ByVal SearchText As String, _
Optional ByVal SplitString As String = ".", _
Optional ByVal JoinString As String = " ") As String
Dim vnt As Variant ' String Array
Dim i As Long ' String Array Element Counter
Dim strB As String ' String Builder
vnt = Split(SearchText, SplitString)
' Loop through elements of String Array.
For i = 0 To UBound(vnt) - 1 ' "-1" ie. Ignore text after last Split String.
' Check value of current element of String Array against SearchString.
' "vbTextCompare" determines case-INsensitivity (AA = aa = Aa = aA).
If InStr(1, vnt(i), SearchString, vbTextCompare) Then
' Build the String
If strB <> "" Then ' For all but the first found SearchString.
strB = strB & JoinString & Trim(vnt(i)) & SplitString
Else ' Only for the first found SearchString.
strB = Trim(vnt(i)) & SplitString
End If
End If
Next
SSS = strB
End Function
Использование в Excel
A1
содержит "apple"
A2
содержит "An apple a day keeps the doctor away. But I don’t think they are yummy. I have never liked them. Apples aren’t my favourite, pears are."
Вв любой другой ячейке напишите следующую формулу:
=SSS(A1, A2)
, чтобы получить следующий результат:
An apple a day keeps the doctor away. Apples aren’t my favourite, pears are.
Замечания
В вашем случае вы можете опустить параметры 3-гои 4-й аргумент:
- 3-й аргумент
SplitString
и по умолчанию DOT
"." - 4-й аргумент
JoinString
и по умолчанию SPACE
"".