|
参与一下。。。- Sub ykcbf() '//2024.1.9
- Application.ScreenUpdating = False
- p = ThisWorkbook.Path
- Set d = CreateObject("Scripting.Dictionary")
- f = p & "\数据源.xlsx"
- Set Sh = ThisWorkbook.Sheets("机械租赁利润表")
- Set Wb = Workbooks.Open(f, 0)
- With Wb.Sheets("机械")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a3:o" & r)
- Wb.Close False
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 2) & "|" & Month(arr(i, 4))
- If Not d.exists(s) Then
- d(s) = Array(arr(i, 6), arr(i, 9))
- Else
- t = d(s)
- t(0) = t(0) + arr(i, 6)
- t(1) = t(1) + arr(i, 9)
- d(s) = t
- End If
- Next
- With Sh
- arr = .Range("a20:e33")
- For j = 2 To UBound(arr, 2) Step 2
- For i = 3 To UBound(arr)
- s = arr(1, j) & "|" & Val(arr(i, 1))
- If d.exists(s) Then
- arr(i, j) = d(s)(0)
- arr(i, j + 1) = d(s)(1)
- End If
- Next
- Next
- .Range("a20:e33") = arr
- .[b34].Resize(1, 4).FormulaR1C1 = "=SUM(R22C:R" & "[-1]C)"
- End With
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|