Lightly tested, but I think that this would work. With the ParamArray, you could search for one or more words being required.
Option Explicit
Public Function ContainsDesiredPattern(ByVal Cell As Range, KillLeadingOrFollowingSpaces As Boolean, ParamArray Words2LookFor() As Variant) As Boolean
' Late-bound|Early-bound
Static REX As Object ' VBScript_RegExp_55.RegExp
Dim strCellText As String
Dim Index As Long
' We used Static, so we only have to create the object once. Test to see if already created...
If REX Is Nothing Then
Set REX = CreateObject("VBScript.RegExp")
With REX
.Global = False
.IgnoreCase = True
End With
End If
If KillLeadingOrFollowingSpaces Then
strCellText = Trim$(Cell.Value)
Else
strCellText = Cell.Value
End If
' Test for 'ARS', if fails, we'll skip further checks
ContainsDesiredPattern = (Left$(strCellText, 3) = "ARS")
If ContainsDesiredPattern Then
'Loop thru the word or words we are requiring
For Index = 0 To UBound(Words2LookFor)
'Simple pattern that looks for existence of the word surrounded by word boundaries
REX.Pattern = "\b" & Words2LookFor(Index) & "\b"
'If we fail our test, the word wasn't found, so flip our flag and exit
If Not REX.Test(strCellText) Then
ContainsDesiredPattern = False
Exit Function
End If
Next
End If
End Function
Sub example()
Dim sCellValue As String
Sheet1.Cells(1).Value = "ARS big house on the hill"
MsgBox "Found value(s) = " & ContainsDesiredPattern(Sheet1.Cells(1), True, "House")
MsgBox "Found value(s) = " & ContainsDesiredPattern(Sheet1.Cells(1), True, "House", "HILL")
MsgBox "Found value(s) = " & ContainsDesiredPattern(Sheet1.Cells(1), True, "House", "HILL", "little")
Sheet1.Cells(1).Value = "Big house on the hill"
MsgBox "Found value(s) = " & ContainsDesiredPattern(Sheet1.Cells(1), True, "House", "HILL")
End Sub
Hope that helps,
Mark