+ Reply to Thread
Results 1 to 3 of 3

help on erasing duplicates in array

Hybrid View

sugee help on erasing duplicates in... 07-04-2013, 01:26 AM
sugee Re: help on erasing... 07-04-2013, 01:57 AM
nilem Re: help on erasing... 07-04-2013, 03:07 AM
  1. #1
    Registered User
    Join Date
    06-24-2013
    Location
    Bursa
    MS-Off Ver
    Excel 2007
    Posts
    22

    Exclamation help on erasing duplicates in array

    I add all values in column 6 in to an array than add them in to comboBox. The problem is there are lots of same values and I could'nt remove the duplicates.
    I 'm sending the files can you help me pls?

    My code is in module 2 and in userForm! button click ..
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    06-24-2013
    Location
    Bursa
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: help on erasing duplicates in array

    Here is my code,
    RemoveDuplicatesInArray don't work
    
    Sub abcd()
      Dim myArray
      Dim exp As Integer
      Dim i As Long
      Dim arr
     
        
        myArray = Range("A6").CurrentRegion
        
        For i = 1 To UBound(myArray, 1)
           
        Next i
        
        arr = RemoveDuplicatesInArray(myArray)
    
      
        For exp = LBound(arr) To UBound(arr)
            UserForm1.ComboBox1.AddItem arr(exp, 1)
        Next exp
        
    UserForm1.Show
    
    End Sub
    
    Public Function RemoveDuplicatesInArray(the_array)
     
        On Error Resume Next
        p = 1
        Do
           Z = UBound(the_array, p)
           p = p + 1
        Loop While Err = 0
        Err = 0
        NumDimensions = p - 2
     
        Dim newArray()
     
        Select Case NumDimensions
     
            Case 1
     
                new_array_nb = 0
                ReDim newArray(0 To 0)
     
                For k = 0 To UBound(the_array)
                    Duplicate = 0
                    For x = 0 To k - 1
                        If the_array(x) = the_array(k) Then
                            Duplicate = 1
                            Exit For
                        End If
                    Next x
                    If Duplicate = 0 And IsEmpty(the_array(k)) = False Then
                        ReDim Preserve newArray(0 To new_array_nb)
                        newArray(new_array_nb) = the_array(k)
                        new_array_nb = new_array_nb + 1
                    End If
                Next k
     
            Case 2
     
                the_dim = UBound(the_array, 1)
     
                new_array_nb = 0
                ReDim newArray(0 To the_dim, 0 To 0)
     
                For k = 0 To UBound(the_array, 2)
                    Duplicate = 0
                    For x = 0 To k - 1
                        equal = 1
                        For eq = 0 To the_dim
                            If the_array(eq, x) <> the_array(eq, k) Then
                                equal = 0
                                Exit For
                            End If
                        Next eq
                        If equal = 1 Then
                            Duplicate = 1
                        End If
                    Next x
                    If Duplicate = 0 Then
                        ReDim Preserve newArray(0 To the_dim, 0 To new_array_nb)
                        For eq = 0 To the_dim
                            newArray(eq, new_array_nb) = the_array(eq, k)
                        Next eq
                        new_array_nb = new_array_nb + 1
                    End If
                Next k
     
            End Select
     
        RemoveDuplicatesInArray = newArray
     
        On Error GoTo 0
     
    End Function

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: help on erasing duplicates in array

    Hi Sugee,
    this is just an example (author of the code ZVI), I deleted the unwanted data from your file
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1