Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created July 11, 2021 05:43
Show Gist options
  • Save ndthanh/d234b8076762234736182efa66f37f6f to your computer and use it in GitHub Desktop.
Save ndthanh/d234b8076762234736182efa66f37f6f to your computer and use it in GitHub Desktop.
Function RemoveDupeWords(text As String, Optional delimiter As String = " ") As String
Dim dictionary As Object
Dim x, part
Set dictionary = CreateObject("Scripting.Dictionary")
dictionary.CompareMode = vbTextCompare
For Each x In Split(text, delimiter)
part = Trim(x)
If part <> "" And Not dictionary.Exists(part) Then
dictionary.Add part, Nothing
End If
Next
If dictionary.Count > 0 Then
RemoveDupeWords = Join(dictionary.keys, delimiter)
Else
RemoveDupeWords = ""
End If
Set dictionary = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment