|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 feilanga 于 2024-1-22 15:20 编辑
字典是一样的道理。模块顶部声明全局字典Public dic全局 As Dictionary
Public dic全局 As Object '声明全局变量,后期绑定
Function 全局字典初始化()
If Not dic全局 Is Nothing Then Exit Function '如果全局字典不为空就退出
Set dic全局 = CreateObject("scripting.dictionary")
Dim arr, i, key
arr = Sheet1.Range("a1:g" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row).Value
'源数据装入字典
For i = 2 To UBound(arr) '从第二行开始循环
key = arr(i, 1) & "," & arr(i, 2) & "," & arr(i, 3) '关键字所在的列
dic全局(key) = dic全局(key) & "," & i '多次记录字典中关键字key对应的行号,用逗号隔开
Next
End Function |
|