|
请参考
- Sub 汇总()
- Dim Arr, i%, j%, drow%, k%, ddrow%, d1, d2, d3, Brr(), k1
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- Set d3 = CreateObject("scripting.dictionary")
- Dim sht As Worksheet '定义sht 为工作表
-
- If Worksheets("汇总").Range("e2") = Worksheets("汇总").Range("d2") Then Exit Sub
- For Each sht In Worksheets
- With sht
-
- If (.Name <> "汇总") And (.Name = "09460600") Then
- drow = .Range("a65536").End(xlUp).Row
- Arr = .Range("a2:g" & drow)
- For i = 2 To UBound(Arr)
- d1(Arr(i, 1) & "@" & Arr(i, 2)) = d1(Arr(i, 1) & "@" & Arr(i, 2)) + Arr(i, 3) * Sheets("汇总").Range("D4")
- Next
- ElseIf (.Name <> "汇总") And (.Name = "09460610") Then
- drow = .Range("a65536").End(xlUp).Row
- Arr = .Range("a2:g" & drow)
- For i = 2 To UBound(Arr)
- d1(Arr(i, 1) & "@" & Arr(i, 2)) = d1(Arr(i, 1) & "@" & Arr(i, 2)) + Arr(i, 3) * Sheets("汇总").Range("D5")
- Next
-
- ElseIf (.Name <> "汇总") And (.Name = "09460650") Then
- drow = .Range("a65536").End(xlUp).Row
- Arr = .Range("a2:g" & drow)
- For i = 2 To UBound(Arr)
- d1(Arr(i, 1) & "@" & Arr(i, 2)) = d1(Arr(i, 1) & "@" & Arr(i, 2)) + Arr(i, 3) * Sheets("汇总").Range("D6")
- Next
-
- End If
- End With
-
- Next
-
- '--------------------------------------copy-------------------------------------
- k1 = d1.keys
- ReDim Brr(0 To d1.Count, 1 To 4)
- For i = 0 To d1.Count - 1
- Brr(i, 1) = Split(k1(i), "@")(0)
- Brr(i, 2) = Split(k1(i), "@")(1)
- Next
- Worksheets("汇总").Range("a10").Resize(d1.Count, 2) = Brr '通过数组把数据复制到目标区域中
- k = 0
- If Cells(9, 5 + k) <> ("PO" & (Range("d2")) & "使用数量") Then
- k = k + 1
- Cells(9, 5 + k) = "PO" & (Range("d2")) & "使用数量"
- Worksheets("汇总").Cells(10, 5 + k).Resize(d1.Count, 1) = Application.Transpose(d1.items) '通过数组把数据复制到目标区域中
- End If
- '------------------------------PO update------------------------------------------------
- Range("e9") = "PO" & (Range("d2")) & "使用数量"
- '---------------------------------------------------------------------------------------
- Worksheets("汇总").Range("e10").Resize(d1.Count, 1) = Application.Transpose(d1.items) '通过数组把数据复制到目标区域中
-
- '--------------------------------------subtraction-------------------------------------
- ddrow = Worksheets("汇总").Range("a65531").End(xlUp).Row
- For j = 10 To ddrow
- Range("D" & j) = Range("C" & j) + Range("D" & j) - Range("E" & j)
- Range("c" & j) = 0
- If Range("D" & j) <= 0 Then
- Cells(j, 4).Font.ColorIndex = 3
- Else
- Cells(j, 4).Font.Color = RGB(0, 0, 255)
- End If
- Next
- For j = 10 To ddrow
- x = Cells(j, 4)
- Cells(j, 4) = x - Cells(j, 5)
- Next
- Worksheets("汇总").Range("e2") = Worksheets("汇总").[d2]
- End Sub
复制代码 |
|