ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to remove duplicate text with comma seperated (https://www.excelbanter.com/excel-programming/437411-re-how-remove-duplicate-text-comma-seperated.html)

RB Smissaert

How to remove duplicate text with comma seperated
 
This will be a lot faster, but bear in mind it will alter the original
string:

Function ReplaceDupsInCSV(str As String) As String

Dim i As Long

For i = Len(str) - 1 To 1 Step -3
If InStr(1, str, Mid$(str, i, 2)) < i Then
Mid$(str, i, 2) = "--"
End If
Next i

ReplaceDupsInCSV = Replace(str, ",--", vbNullString)

End Function


You could make it a lot faster still if you use one of the Replace functions
he
http://www.xbeat.net/vbspeed/c_Replace.htm


RBS


"geniusideas" wrote in message
...
Hi,

In VBA how to remove duplicate text seperated by comma example :

Example : One Cells contained

Before - AE,AE,DE,BE,CE,CE,FE,GE,GE

After - AE,DE,BE,CE,FE,GE

Can some one give me the code.Thanks




All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com