我有大字典键,我想插入excel表的列。我在下面做了什么:
Dim a, d, i 'Create some variables
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" 'Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
a = d.keys 'Get the keys
For i = 0 To d.Count - 1 'Iterate the array
ob.Cells(i + 1, 1).Value = a(i)
Next
但是可以在一个声明中完成吗?说obj2.Cells(1,1).Resize(dicP.Count,1)=a
我也试过了这个,但它只放了我在Resize
定义的范围内的第一个键。
答案 0 :(得分:3)
喜欢这个吗?
Sub a()
Dim d '<~~ Create some variable
Dim sKeys()
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" 'Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
'~~> Get dictionary Keys
sKeys = d.keys
Range("A1").Resize(d.Count) = Application.Transpose(sKeys)
End Sub