remove duplicated persian word seperated with comma in a cell

osmanoca

Board Regular
Joined
Apr 16, 2016
Messages
87
hello, i have a macro to delete dublicated words and seperated with comma in same cell . but it works in english character languages. but it doesnt delete persian words. what is problem? please help.

my data is so


A B
nav اسم،اسم،نام،اسم،نام
pênûs قلم،مداد،مداد،قلم
çay چاي, چای‬, چای,جویبار, چای



i want them to beo so:
nav اسم،نام
pênûs مداد،قلم
çay جویبار, چای


please please help.
 
Re: remove dublicated persian word seperated with comma in a cell

Comment out the line in red and see if that is better.

Code:
                word_coll.Add word_ary(0), word_ary(0)
                txt = word_ary(1)
                
                ' Split the remaining words on the commas.
                txt = Replace(txt, ChrW(1548), "|")
                txt = Replace(txt, ",", "|")
                [COLOR=#b22222]' txt = Replace(txt, " ", "")[/COLOR]
                word_ary = Split(txt, "|")
                
                ' Remove the duplicates.
                On Error Resume Next
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Re: remove dublicated persian word seperated with comma in a cell

i removed red texts and made as below but still removing spaces.

------------------------------------------------------
word_coll.Add word_ary(0), word_ary(0) txt = word_ary(1)


txt = Replace(txt, ChrW(1548), "|")
txt = Replace(txt, ",", "|")
txt = Replace(txt, " ", "")
word_ary = Split(txt, "|")


For Each word In word_ary
On Error Resume Next
------------------------------------------------------------------
 
Upvote 0
Re: remove dublicated persian word seperated with comma in a cell

It appears you removed a different line, not the one I wanted you to remove.

Here is the complete macro as I have it. It works with the few examples I have to test.

Code:
Sub RemovePersianDuplicates()
    Dim ary As Variant
    Dim dict As Object
    Dim i As Long, j As Long, k As Long
    Dim latin_comma As Boolean
    Dim rng As Range
    Dim txt As String
    Dim word As Variant
    Dim word_ary As Variant
    Dim word_coll As New Collection
    
    Application.ScreenUpdating = False
    
    With ActiveSheet
        Set rng = Intersect(Range(.Columns(1), .Columns(7)), .UsedRange)
    End With
    
    ary = rng.Value2

    For i = LBound(ary, 1) To UBound(ary, 1)
        For j = LBound(ary, 2) To UBound(ary, 2)
            txt = CStr(ary(i, j))

            ' Parse txt only if it contains more than one word.
            If txt <> "" And InStr(Trim(txt), " ") > 0 Then
            
                ' Remove the POP DIRECTIONAL FORMATTING character, U+202C.
                txt = Replace(txt, ChrW(&H202C), "")
                
                ' Change Farsi YEH to Arabic YEH.
                txt = Replace(txt, ChrW(1740), ChrW(1610))
                
                ' Latin comma+space or Persian comma with no space?
                latin_comma = True
                If InStr(txt, ChrW(1548)) > 0 Then latin_comma = False
                
                ' Grab the first Latin word.
                txt = Replace(txt, " ", "|", Count:=1)
                word_ary = Split(txt, "|")
                word_coll.Add word_ary(0), word_ary(0)
                txt = word_ary(1)
                
                ' Split the remaining words on the commas.
                txt = Replace(txt, ChrW(1548), "|")
                txt = Replace(txt, ",", "|")
                ' txt = Replace(txt, " ", "")
                word_ary = Split(txt, "|")
                
                ' Remove the duplicates.
                On Error Resume Next
                For Each word In word_ary
                    word_coll.Add word, word
                Next word
                On Error GoTo 0
                
                ' Reassemble the entire string.
                txt = word_coll(1)
                For k = 2 To word_coll.Count
                    If k = 2 Then
                        txt = txt & " " & word_coll(k)
                    ElseIf latin_comma Then
                        txt = txt & ", " & word_coll(k)
                    Else
                        txt = txt & ChrW(1548) & word_coll(k)
                    End If
                Next k
                
                ary(i, j) = txt
                Set word_coll = Nothing
            End If
        Next j
    Next i
    
    ' Send the texts to the worksheet.
    rng.Value2 = ary
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Re: remove dublicated persian word seperated with comma in a cell

this code is adding space to after comma. doesnt remove anthing. sorry.
 
Upvote 0
Re: remove dublicated persian word seperated with comma in a cell

Would you please post more examples.

This is what happens when I run the newest macro:

[TABLE="class: grid"]
<tbody>[TR]
[TD="align: left"]Before
[/TD]
[TD="align: left"]After[/TD]
[/TR]
[TR]
[TD="align: right"]قبل ازاينکه[/TD]
[TD="align: right"]قبل ازاينکه[/TD]
[/TR]
[TR]
[TD="align: right"]علاوه بر آن که[/TD]
[TD="align: right"]علاوه بر آن که[/TD]
[/TR]
[TR]
[TD="align: left"]apple قبل از اینکه[/TD]
[TD="align: left"]apple قبل از اينکه[/TD]
[/TR]
[TR]
[TD="align: left"]berry علاوه بر آن که[/TD]
[TD="align: left"]berry علاوه بر آن که[/TD]
[/TR]
[TR]
[TD="align: left"]nav اسم،اسم،نام،اسم،نام[/TD]
[TD="align: left"]nav اسم،نام[/TD]
[/TR]
[TR]
[TD="align: left"]pênûs قلم،مداد،مداد،قلم[/TD]
[TD="align: left"]pênûs قلم،مداد[/TD]
[/TR]
[TR]
[TD="align: left"]çay چاي, چای‬, چای,جویبار, چای[/TD]
[TD="align: left"]çay چاي, چاي, جويبار[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Re: remove dublicated persian word seperated with comma in a cell

i used your code again as you said, but the result is same .it is adding spaces as i said. sorry..
 
Upvote 0
Re: remove dublicated persian word seperated with comma in a cell

ok it is working. i saw. no problem. thanks. really. thanks...
 
Upvote 0
Re: remove dublicated persian word seperated with comma in a cell

Oh, good! It's working OK for you. Thank you for the update.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top