Unique values from 1D-array, without iteration

后端 未结 4 765
陌清茗
陌清茗 2021-01-13 19:25

At risk of being of topic, I decided to share some code, Q&A-style. If the general opinion is such that this would be off-topic I\'ll be happy to delete if need be.

4条回答
  •  盖世英雄少女心
    2021-01-13 19:48

    With the new Dynamic Array functions it can be simplified to:

    Sub test()
    
    Dim arr As Variant: arr = Array("A", "A", "C", "D", "A", "E", "G")
    With Application
        Dim uniques as variant
        uniques = .Transpose(.Unique(.Transpose(arr)))
    End With
    
    End Sub
    

    The new Uniques Formula needs a vertical array, and it can be 2d. It acts like Range.RemoveDuplicate without the ability to choose columns.

提交回复
热议问题