|
又做了个字典嵌套的。- Sub test2()
- Dim d As Object
- Dim d1 As Object
- Dim r%, i%
- Dim arr, brr()
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
-
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 6).End(xlUp).Row
- arr = .Range("f3:g" & r)
- End With
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- n = d(arr(i, 1)).Count + 1
- d(arr(i, 1))(n) = arr(i, 2)
- Next
-
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3:c" & r)
- For i = 1 To UBound(arr)
- If d.Exists(arr(i, 2)) Then
- d1(arr(i, 2)) = d1(arr(i, 2)) + 1
- If d(arr(i, 2)).Exists(d1(arr(i, 2))) Then
- arr(i, 3) = d(arr(i, 2))(d1(arr(i, 2)))
- End If
- End If
- Next
- .Range("a3").Resize(UBound(arr), 3) = arr
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|