Sub 编写字典() Dim d As New Dictionary For i = 1 To 4 d(Cells(i, 1).Value) = Cells(i, 2) Next i MsgBox d("男孩") Set d = Nothing End Sub
=========================================================== Sub 修改字典() Dim d As New Dictionary For i = 1 To 4 d(Cells(i, 1).Value) = Cells(i, 2) Next i d("男孩") = "myboy" MsgBox d("男孩") Set d = Nothing End Sub
=============================================== Sub 唯一的编号字典方法() 'Set d = CreateObject("Scripting.Dictionary") Dim d As New Dictionary Dim arr1, arr2, x As Integer, y As Integer, t t = Timer Range("d2:d" & Range("d65536").End(xlUp).Row) = "" arr1 = Range("a2:b11") arr2 = Range("b2:b11") mrow1 = UBound(arr1) mrow2 = UBound(arr2) ReDim arr3(1 To mrow1 + mrow2, 1 To 1) For x = 1 To mrow1 d(arr1(x, 1)) = "" Next x For y = 1 To mrow2 d(arr2(y, 1)) = "" Next y Range("d2").Resize(d.Count, 1) = Application.Transpose(d.Keys) MsgBox Timer - t End Sub