gpt4 book ai didi

vba:从数组中获取唯一值

转载 作者:行者123 更新时间:2023-12-01 16:25:40 26 4
gpt4 key购买 nike

中有任何内置功能吗?从一维数组中获取唯一值?只删除重复项怎么样?

如果没有,那么我如何从数组中获取唯一值?

最佳答案

This post包含 2 个示例。我喜欢第二个:

Sub unique() 
Dim arr As New Collection, a
Dim aFirstArray() As Variant
Dim i As Long

aFirstArray() = Array("Banana", "Apple", "Orange", "Tomato", "Apple", _
"Lemon", "Lime", "Lime", "Apple")

On Error Resume Next
For Each a In aFirstArray
arr.Add a, a
Next
On Error Goto 0 ' added to original example by PEH

For i = 1 To arr.Count
Cells(i, 1) = arr(i)
Next

End Sub

关于vba:从数组中获取唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3017852/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com