Results 1 to 14 of 14

Thread: Getting Unique elements of Array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,773
    You could do something like this, without Collection or Dictionary Objects.

    Dim myArray As Variant, UniqueArray As Variant
    Dim pointer As Long
    Dim i As Long
    myArray = Array("apple", "bat", "apple", "cat", "battery", "bat", "fish")
    UniqueArray = myArray
    pointer = LBound(UniqueArray) - 1
    For i = LBound(UniqueArray) To UBound(UniqueArray)
        If pointer < Application.Match(UniqueArray(i), UniqueArray, 0) - (1 - LBound(UniqueArray)) Then
            pointer = pointer + 1
            UniqueArray(pointer) = UniqueArray(i)
        End If
    Next i
    ReDim Preserve myArray(LBound(UniqueArray) To pointer)
    MsgBox Join(UniqueArray)
    Last edited by Aussiebear; 01-01-2025 at 12:12 PM.

Posting Permissions

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