|
本帖最后由 中原一布衣 于 2012-8-10 16:16 编辑
谢了!好好学学!今后肯定用得着!!简单的数据汇总:
Sub bbhz()
Dim i&, Myr&, Arr
Application.ScreenUpdating = False
Set d = CreateObject("Scripting.Dictionary")
Set d1 = CreateObject("Scripting.Dictionary")
Myr = Sheets("收料单").[a65536].End(xlUp).Row
Arr = Sheets("收料单").Range("a2:d" & Myr) 'A1:D1分别为材料编号,数量,金额,期间
Range("a2:c" & Myr).ClearContents '汇总前清除原先内容
qj = Range("D1").Value '按月份汇总
For i = 1 To UBound(Arr)
If Arr(i, 4) = qj Then '若全部汇总,则IF语句省去即可
s = Arr(i, 1) '材料编号
d(s) = d(s) + Arr(i, 2) '数量汇总
d1(s) = d1(s) + Arr(i, 3) '金额汇总
End If
Next
k = d.Keys
t = d.items
t1 = d1.items
[a2].Resize(d.Count, 1) = Application.Transpose(k)
[b2].Resize(d.Count, 1) = Application.Transpose(t)
[c2].Resize(d.Count, 1) = Application.Transpose(t1)
Application.ScreenUpdating = True
End Sub
|
|