Showing posts with label Remove duplcate values from an array using VBA. Show all posts
Showing posts with label Remove duplcate values from an array using VBA. Show all posts

Sunday, April 10, 2022

Remove duplcate values from an array using VBA

 arr1 = Range(Range("C13"), Range("C13").End(xlDown)).Value2
arr2 = Range(Range("E13"), Range("E13").End(xlDown)).Value2
'arr2 = ws.Range("E13:E25").Value2
    
arr3 = Split(Join(Application.Transpose(arr1), ",") & "," & Join(Application.Transpose(arr2), ","), ",")
'Debug.Print Join(arr3, ",")

Dim poArrNoDup()
Dim duparrindex As Integer

    duparrindex = -1
    For i = LBound(arr3) To UBound(arr3)
        dupBool = False

        For j = LBound(arr3) To i
            If arr3(i) = arr3(j) And Not i = j Then
                dupBool = True
            End If
        Next j

        If dupBool = False Then
            duparrindex = duparrindex + 1
            ReDim Preserve poArrNoDup(duparrindex)
            poArrNoDup(duparrindex) = arr3(i)
        End If
    Next i