我得到了一个包含各种数据的表。在一列中,我们发现了一些不时发生的项目编号。我想创建包含每个项目编号的列表。VBA:在列中选择唯一值,将它们添加到数组并将数组写入表中
所以我想创建一个数组并添加数字给它,如果它不存在于现有的数组中。
最后的阵列应该在表格中显示
这是我已经想出迄今:
Sub ChoseNumbers()
' Chosing the Numbers in the AreaDim Arr() As Integer
Dim i As Integer
Dim area As Range
Set area = Columns("N").cells
i = 0
For Each cell In area
If IsEmpty(cell) Then
Exit For
ElseIf i = 0 Then
ReDim Preserve Arr(i)
Arr(UBound(Arr)) = cell.Value
i = i + 1
ElseIf IsInArray(cell.Value, Arr) = False Then
ReDim Preserve Arr(i)
Arr(UBound(Arr)) = cell
i = i + 1
End If
Next cell
'Giving the selection out again
For i = 1 To (UBound(Arr))
cells(i, 1).Value = Arr(i)
Next i
End Sub
谢谢你的建议!
或更高版本有删除重复功能,这将做到这一点......数据>数据工具>删除重复 – Skytunnel
感谢您的提示!但是,我需要它作为一个数组,因为我将来也需要其他程序。最好的,f –