返回列表 上一主題 發帖

如何做跨頁出貨單歷史統計

本帖最後由 GBKEE 於 2011-5-8 20:01 編輯

回復 1# janejacky

更正:
試試看
  1. Sub Ex()
  2.     Dim D(2) As Object, R As Variant, AR()
  3.     Set D(0) = CreateObject("Scripting.Dictionary")
  4.     Set D(1) = CreateObject("Scripting.Dictionary")
  5.     Set D(2) = CreateObject("Scripting.Dictionary")
  6.     With Sheets("出貨單")
  7.         For Each R In .Range(.[B12], .[G29]).Rows   '出貨單內容範圍-> 的整列
  8.             If Application.CountA(R) = 6 Then   '資料要齊全
  9.                 AR = Array(.[G4].Text, .[G5], .[B5], R.Cells(1, 1), R.Cells(1, 2), R.Cells(1, 3), R.Cells(1, 5), R.Cells(1, 6))
  10.                 D(1)(Join(AR, ",")) = AR
  11.             End If
  12.         Next
  13.     End With
  14.     With Sheets("出貨單歷史統計")
  15.         For Each R In .Range(.[A3], .Cells(Rows.Count, "H").End(xlUp)).Rows
  16.             If Application.CountA(R) = 8 Then D(0)(Join(Application.Transpose(Application.Transpose(R.Value)), ",")) = ""
  17.             D(2)(R.Cells(1, 1) & R.Cells(1, 2)) = D(2)(R.Cells(1, 1) & R.Cells(1, 2)) + R.Cells(1, 8)
  18.         Next
  19.         For Each R In D(1).KEYS
  20.             If D(0).EXISTS(R) = False Then
  21.                 With .Cells(Rows.Count, "A").End(xlUp).Offset(1)
  22.                     .Resize(, 8) = D(1)(R)
  23.                     D(2)(.Cells(1) & .Cells(1, 2)) = D(2)(.Cells(1) & .Cells(1, 2)) + .Cells(1, 8)
  24.                 End With
  25.             End If
  26.         Next
  27.         For Each R In .Range(.[A3], .Cells(Rows.Count, "A").End(xlUp))
  28.             If D(2).EXISTS(R & R(1, 2)) Then R(1, 9) = D(2)(R & R(1, 2))
  29.         Next
  30.     End With
  31.     Set D(0) = Nothing
  32.     Set D(1) = Nothing
  33.     Set R = Nothing
  34. End Sub
複製代碼

TOP

        靜思自在 : 我們最大的敵人不是別人.可能是自己。
返回列表 上一主題