2011-07-21 68 views
0

我需要根據存儲在VBA中的字典(Set dict = CreateObject(「Scripting.Dictionary」))中的值創建一個柱狀圖。 x軸是鍵,y軸是值。有沒有辦法做到這一點?從VBA中的字典值創建柱狀圖

回答

0

試試這個:

Public Sub WriteDictionary() 

    Dim dict As Variant 
    Dim currRow As Integer 


    Set dict = CreateObject("Scripting.Dictionary") 
    currRow = 1 

    dict.Add "key 1", "data 1" 
    dict.Add "key 2", "data 2" 

    For Each Key In dict.Keys 
     Range("A" & currRow).Formula = Key 
     Range("B" & currRow).Formula = dict(Key) 
     currRow = currRow + 1 
    Next Key 

    Set dict = Nothing 

End Sub