|
本帖最后由 一烟难禁 于 2022-12-19 14:47 编辑
- Sub test()
- Dim h, i, j, k, arr, zrr, ss, tt
- arr = Sheets("工作表2").Range("a1").CurrentRegion
- zrr = Sheets("工作表1").Range("a1").CurrentRegion
- Dim dic As Object
- Set dic = CreateObject("scripting.dictionary")
- For h = 2 To UBound(arr)
- ss = arr(h, 1) & "#" & arr(h, 2)
- dic(ss) = dic(ss) + arr(h, 3)
- Next
- For i = 2 To UBound(zrr)
- For j = 4 To UBound(zrr, 2)
- tt = zrr(i, 1) & "#" & zrr(1, j)
- If dic.exists(tt) Then
- zrr(i, j) = dic(tt)
- End If
- Next
- Next
- For i = 2 To UBound(zrr)
- k = 0
- For j = 3 To UBound(zrr, 2)
- If zrr(i, j) <> "" Then
- zrr(i, 3) = zrr(i, 3) + zrr(i, j)
- k = k + 1
- End If
- zrr(i, 2) = k
- Next
- Next
- Sheets("工作表1").Range("a1").CurrentRegion = zrr
- End Sub
复制代码
你这个数据量不算大,函数也可以的 |
|