一、数据展示
二、代码
Sub 选中区域数据去重()
Dim arr()
Dim c, d, i
d = Selection.Count
i = 0
For Each c In Selection
If c.Value <> "" Then
ReDim Preserve arr(0 To i)
arr(i) = c.Value
i = i + 1
End If
Next
arr = 一维去重(arr)
i = 0
For Each c In Range("O2").Resize(UBound(arr) - LBound(arr) + 1, 1)
c.Value = arr(i)
i = i + 1
Next
End Sub
Function 一维去重(arr)
Dim i&, s, keys
Dim dic
Set dic = CreateObject("scripting.dictionary")
For i = LBound(arr) To UBound(arr) '去重
If arr(i) <> "" Then
If Not dic.Exists(arr(i)) Then dic.Add arr(i), Nothing
End If
Next
ReDim dataarr(0 To dic.Count - 1)
keys = dic.keys
For i = 0 To dic.Count - 1
dataarr(i) = keys(i)
Next
一维去重 = dataarr
End Function