當前位置:成語大全網 - 新華字典 - VBA,可以直接把字典轉換成二維數組嗎

VBA,可以直接把字典轉換成二維數組嗎

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