Function value_to_key(dict1) '用字典的值匹配key Dim arr As New arr Set dict22 = CreateObject("scripting.dictionary") value1 = dict1.items key1 = dict1.keys For z = LBound(dict1.keys) To UBound(dict1.keys) dict22(value1(z)) = Array() Next For z = LBound(dict1.keys) To UBound(dict1.keys) a1 = dict22(value1(z)) b1 = key1(z) dict22(value1(z)) = arr.extend(a1, key1(z)) Next valu_end = dict22.items key_end = dict22.keys For z = LBound(dict22.keys) To UBound(dict22.keys) a1 = valu_end(z) dict22(key_end(z)) = Join(a1, "_") Next Set value_to_key = dict22 End Function Function to_dict(arr1, num1, num2) '指定数组列成字典 Set dict1 = CreateObject("scripting.dictionary") For i = LBound(arr1) To UBound(arr1) dict1(arr1(i, num1)) = arr1(i, num2) Next Set to_dict = dict1 End Function Function to_dict2(arr1, arr2) '两个一维数组成字典 a = UBound(arr1) b = UBound(arr2) If a = b Then Set dict1 = CreateObject("scripting.dictionary") For i = LBound(arr1) To UBound(arr1) dict1(arr1(i)) = arr2(i) Next Set to_dict2 = dict1 Else MsgBox "两组数据长度不同,无法对应匹配" Set to_dict2 = Nothing End If End Function Function dict_union(dict1, dict2) '合并两个字典 For Each key1 In dict2.keys dict1(key1) = dict2(key1) Next Set dict_union = dict1 End Function
标签:Function,Set,dict1,keys,dict22,dict,arr1 From: https://www.cnblogs.com/szd001/p/18395402