I need to remove duplicate words from within a string. I found code to do it and it works but a little too well. The code below will remove anything that is repeated again even if it is just part of a word.
Ex: construction company t shirts construction shirt construction co t shirt
Becomes: construction company shirts
What I want: construction company t shirts shirt co
How can I make this code remove the duplicates while not removing anything that is part of another word?
Public Function EliminateDupesInString(strText As String, Optional strDelim As String = " ") As String
' remove duplicate strings from within a longer string
' "AIRTEX 1241 AIRTEX AW3409 CHRYSLER 7700598025 CHRYSLER JR775056 DELPHI DD1265 DELPHI DD1666 DELPHI WP1039 DELPHI WP1747 DELPHI WP2235 RENAULT 7700598025"
' becomes "AIRTEX 1241 AW3409 CHRYSLER 7700598025 JR775056 DELPHI DD1265 DD1666 WP1039 WP1747 WP2235 RENAULT"
Dim varArray As Variant
Dim intI As Integer
Dim strOut As String
strText = " " & strText & " "
varArray = Split(strText, strDelim)
For intI = 0 To UBound(varArray) - 1
If InStr(strOut, varArray(intI)) = 0 Then
strOut = strOut & varArray(intI) & " "
EliminateDupesInString = Trim(strOut)