So I've got a list of strings, for which some of the strings contain duplicates.
For example:
13-Hexadecenoic acid;13-methyl-4-pentadecenoic acid;14-Methyl-6-pentadecenoic acid;15-Hexadecanolide;3-Hexadecenoic acid;4-hexadecenoic acid;13-Hexadecenoic acid;13-methyl-4-pentadecenoic acid;14-Methyl-6-pentadecenoic acid;15-Hexadecanolide;3-Hexadecenoic acid;4-hexadecenoic acid;
So I came across a macro online and tweaked it to work for my problem, which goes like this:
Function stringOfUniques(inputString As String) As String
Dim inArray() As String
Dim xVal As Variant
inArray = Split(inputString, ";")
For Each xVal In inArray
If InStr(stringOfUniques, Trim(xVal)) = 0 Then _
stringOfUniques = stringOfUniques & Trim(xVal) & ","
Next xVal
End Function
And for some of my strings this works brilliantly, however for the example above it will return the string with the duplicates removed, but weirdly will get rid off both copies of one of the words '3-Hexadecenoic acid'. So basically
What I should get:
13-Hexadecenoic acid;13-methyl-4-pentadecenoic acid;14-Methyl-6-pentadecenoic acid;15-Hexadecanolide;3-Hexadecenoic acid;4-hexadecenoic acid;
What I actually get:
13-Hexadecenoic acid;13-methyl-4-pentadecenoic acid;14-Methyl-6-pentadecenoic acid;15-Hexadecanolide;4-hexadecenoic acid;
Is there something in my code that's causing this to happen?
InStr-> Returns an integer specifying the start position of the first occurrence of one string within another. So it probably is going to treat13-Hexadecenoic acidas a duplicate of3-Hexadecenoic acidThus even after removing the first3-Hexadecenoic acidit will still find13-Hexadecenoic acidand remove the second