Dictionary object in VBA (corresponding to the java Map) using Summary

VBA in the Dictionary object to use summary
2005-11-15

VBA in the Dictionary object to use Summary

Dim dict

' 创建Dictionary
Set dict = CreateObject("Scripting.Dictionary")

' 增加项目
dict.Add "A", 300
dict.Add "B", 400
dict.Add "C", 500

'Statistical item number
n = dict.Count

'Remove items
dict.Remove ( "A")

'It is determined whether the dictionary contains the keyword
dict.exists ( "B")

'Take a value corresponding to the keyword, determines whether there is key attention to the need before use, otherwise it will be more of a dict record
Value = dict.Item ( "B")

'Key corresponding to the modified value, if not exist, create a new project
dict.Item ( "B") = 1000
dict.Item ( "D") = 800

'Cycle of dictionary
K = dict.keys
V = dict.Items
the For I = 0 the To dict.Count -. 1
Key = K (I)
the Value = V (I)
MsgBox the Value Key &
the Next

'Delete all items
dict.Removeall

Example:

Sub Macro 1 ()

Set dic = CreateObject ( "Scripting.Dictionary" ) ' Dictionary
the For I = 10000. 1 the To
the If Not I Like " . 4 " the Then
dic.Add I, ""' If it does not ". 1"
End the If
the Next
the Range ( "A2") .Resize (dic.Count, 1) = Application.WorksheetFunction.Transpose (dic.keys) ' means disposed downwardly starting from A2
End Sub

Guess you like

Origin www.cnblogs.com/lbsjs/p/11588251.html