第1个回答 2018-06-27
Public Sub qqq()
Dim d As Object, ar, br(), i, n, a, b
Set d = CreateObject("scripting.dictionary")
ar = Range("b2:c" & [a2].End(4).Row)
ReDim br(1 To UBound(ar), 1 To 2)
For i = 1 To UBound(ar)
If ar(i, 1) <> "" And Not d.exists(ar(i, 1)) Then
d(ar(i, 1)) = ar(i, 2)
End If
Next
a = d.keys
b = d.items
For i = 0 To UBound(a)
n = n + 1
br(n, 1) = a(i)
br(n, 2) = b(i)
Next
End Sub本回答被提问者采纳
第2个回答 2023-02-01
Function DicToArr(dic)
'字典写入一个二维数组
Dim i, keys
ReDim arr(1 To dic.Count, 1 To 2)
keys = dic.keys
For i = 0 To dic.Count - 1
arr(i + 1, 1) = keys(i)
arr(i + 1, 2) = dic(keys(i))
Next
DicToArr = arr
End Function