|
- Sub 盘点汇总()
- Dim d As Object, arr, x&, y%, s, t, a, b, m%, n%, r%
- Dim sh As Worksheet
- Application.ScreenUpdating = False
- Set d = CreateObject("scripting.dictionary")
- Application.DisplayAlerts = False
- For f = Sheets.Count To 3 Step -1
- Sheets(f).Delete
- Next f
- Application.DisplayAlerts = True
- Sheets.Add(after:=Sheets(Sheets.Count)).Name = "盘点汇总"
- Sheets("sheet2").Activate
- arr = Range("a1").CurrentRegion
- For x = 2 To UBound(arr)
- If Not d.exists(arr(x, 1)) Then
- Set d(arr(x, 1)) = CreateObject("scripting.dictionary")
- End If
- d(arr(x, 1))(arr(x, 2)) = d(arr(x, 1))(arr(x, 2)) + arr(x, 5)
- Next x
- s = d.keys: t = d.items
- Sheets("盘点汇总").Activate
- For m = 0 To d.Count - 1
- a = d(s(m)).keys: b = d(s(m)).items
- n = n + r
- With Sheets("盘点汇总")
- .Cells(1, 1).Resize(1, 3) = Array("物料代码", "库位", "库存量")
- .Cells(2 + n, 1).Resize(d(s(m)).Count, 1) = s(m)
- .Cells(2 + n, 2).Resize(d(s(m)).Count, 1) = Application.Transpose(a)
- .Cells(2 + n, 3).Resize(d(s(m)).Count, 1) = Application.Transpose(b)
- n = 0
- End With
- r = Cells(Rows.Count, 1).End(xlUp).Row - 1
- Next m
- Range("a:c").EntireColumn.AutoFit
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|