The code below finds a string in a cell and extracts both the search word and the word that come before it.
When the search word is left as "(hello)" the code works but when I make it "(hello hey)" the code cannot find it. I assume its the white space in between "hello" and "hey" but I'm not sure how to make that change.
Dim c As Range, v As String, arr, x As Long, e
Dim d As Range
Set d = WorkSheets("Sheet1").Range("F1") '<<results start here
For Each c In ActiveSheet.Range("D1:D10")
v = Trim(c.Value)
If Len(v) > 0 Then
'normalize other separators to spaces
v = Replace(v, vbLf, " ")
'remove double spaces
Do While InStr(v, " ") > 0
v = Replace(v, " ", " ")
Loop
'split to array
arr = Split(v, " ")
For x = LBound(arr) To UBound(arr)
e = arr(x)
'see if array element is a word of interest
If Not IsError(Application.Match(LCase(e), Array("(hello hey)"), 0)) Then
If x > LBound(arr) Then
d.Value = arr(x - 1) & " " & e 'prepend previous word
Else
d.Value = "??? " & e 'no previous word
End If
Set d = d.Offset(1, 0)
End If
Next x
End If
Next c
End Sub

arrwill contain spaces).