改一下,以适应可能的- Sub ykcbf() '//2024.7.21
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- r1 = Cells(Rows.Count, 2).End(3).Row
- r2 = Cells(Rows.Count, 10).End(3).Row
- Max = IIf(r1 < r2, r2, r1) + 2
- Cells(Max, 1).Resize(23 - Max, 18).ClearContents
- For i = 10 To Max - 2
- If Cells(i, 3) <> Empty Then
- s = UCase(Cells(i, 3)) & "|" & UCase(Cells(i, 4))
- d(s) = ""
- d1(s) = d1(s) + Cells(i, 5)
- End If
- If Cells(i, 11) <> Empty Then
- s = UCase(Cells(i, 11)) & "|" & UCase(Cells(i, 12))
- d(s) = ""
- d2(s) = d2(s) + Cells(i, 13)
- End If
- Next
- ReDim brr(1 To d.Count, 1 To 3)
- For Each k In d.keys
- m = m + 1
- brr(m, 1) = Split(k, "|")(0)
- brr(m, 2) = Split(k, "|")(1)
- brr(m, 3) = d(k)
- Next
- If m > 5 Then
- For i = 1 To m - 5
- Cells(Max + i, 1).EntireRow.Insert
- Next i
- End If
- Cells(Max, 3).Resize(m, 3) = brr
- Cells(Max, 11).Resize(m, 3) = brr
- Cells(Max, 1).Resize(m) = "合计:"
- For i = Max To m + Max - 1
- s = Cells(i, 3) & "|" & Cells(i, 4)
- Cells(i, 5) = d1(s)
- s = Cells(i, 11) & "|" & Cells(i, 12)
- Cells(i, 13) = d2(s)
- Cells(i, 18) = Cells(i, 5) - Cells(i, 13)
- Next
- Set d = Nothing
- MsgBox "OK!"
- End Sub
复制代码
左少右多的情况。
|