Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Simple VBA Excel User Defined Function for adding modified broad match plus signs onto keywords . Also contains a TRUE or FALSE modifier to remove any common word (eg. the, a, for, etc...)
Function MakeModifiedBroadMatch(rng As Range, RemoveCommonWords As Boolean) As String
Dim WordList() As String
Dim CommonWords() As String: CommonWords = Split("how,do,i,with,in,a,to,the,for,is,of,and,are", ",")
Dim i As Integer
Dim x As Integer
Dim ContainsCommonWord As Boolean
Dim ModifiedBroadMatchKeyword As String
WordList = Split(rng.Value)
ContainsCommonWord = False
For i = LBound(WordList) To UBound(WordList)
For x = LBound(CommonWords) To UBound(CommonWords)
If (LCase(WordList(i)) = LCase(CommonWords(x))) And RemoveCommonWords = True Then
ContainsCommonWord = True
End If
Next x
If ContainsCommonWord = False Then
ModifiedBroadMatchKeyword = ModifiedBroadMatchKeyword & " +" & WordList(i)
End If
ContainsCommonWord = False
Next i
MakeModifiedBroadMatch = LTrim(ModifiedBroadMatchKeyword)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment