Removing dubs from array

Temporary-Failure

Board Regular
Joined
Jul 16, 2010
Messages
140
I use code below. But from some reason following strings makes empty result. What's wrong?

Y-column strings:
sku=PFF12-201+powerflex=PFF12-201|sku=PFF12-201+powerflex=PFF12-201
sku=PFF19-601+powerflex=PFF19-601|sku=PFF19-602+powerflex=PFF19-602|sku=PFF19-901+powerflex=PFF19-901|sku=PFF19-601+powerflex=PFF19-601|sku=PFF19-602+powerflex=PFF19-602|sku=PFF19-901+powerflex=PFF19-901

VBA Code:
Sub Test()
Application.Calculation = xlCalculationManual
Application.EnableEvents = False

    Dim arr1, arr2
    rivi = 2
    Do Until Range("A" & rivi).Value = ""
    arr1 = Split(Range("Y" & rivi).Value, "|")

    arr2 = RemoveDupes(arr1)
    'Debug.Print Join(arr2, vbLf)
    Range("AD" & rivi).Value = Join(arr2, "|")
   
    rivi = rivi + 1
    Loop
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
End Sub

Function RemoveDupes(InputArray) As Variant
    Dim Array_2()
    Dim eleArr_1 As Variant
    Dim x As Integer
    x = 0
    On Error Resume Next
    For Each eleArr_1 In InputArray
        If UBound(Filter(InputArray, eleArr_1)) = 0 Then
            ReDim Preserve Array_2(x)
            Array_2(x) = eleArr_1
            x = x + 1
        End If
    Next
    RemoveDupes = Array_2
End Function
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
VBA Code:
Function RemoveDupes(InputArray) As Variant
   Dim eleArr_1 As Variant

   With CreateObject("scripting.dictionary")
      For Each eleArr_1 In InputArray
         .Item(eleArr_1) = Empty
      Next eleArr_1
      RemoveDupes = .Keys
   End With
End Function
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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