|
本帖最后由 mjzxlmg 于 2011-12-26 23:01 编辑
这是求D13的
Sub test()
Dim i&, Myr&, Arr, d As Object, k As Long
Set d = CreateObject("Scripting.Dictionary")
With Sheet1
Myr = .Cells(Rows.Count, 1).End(xlUp).Row - 1
Arr = .Range("a1:c" & Myr)
For i = 2 To UBound(Arr)
s = Left(Arr(i, 1), 3)
If s = "D13" Then
d(s) = d(s) + Arr(i, 3)
End If
Next
MsgBox Application.Transpose(d.keys)(1) & "开头的货品库存量有:" & Application.Transpose(d.items)(1)
.[F2].Value = Application.Transpose(d.keys)(1) & "开头的货品库存量有:" & Application.Transpose(d.items)(1)
End With
Set d = Nothing
End Sub
这是求所有前三位的:
Sub test2()
Dim i&, Myr&, Arr, d As Object
Set d = CreateObject("Scripting.Dictionary")
With Sheet1
Myr = .Cells(Rows.Count, 1).End(xlUp).Row - 1
Arr = .Range("a1:c" & Myr)
For i = 2 To UBound(Arr)
s = Left(Arr(i, 1), 3)
d(s) = d(s) + Arr(i, 3)
Next
.[F2].Resize(d.Count, 1).Value = Application.Transpose(d.keys)
.[g2].Resize(d.Count, 1).Value = Application.Transpose(d.items)
.[f1].Resize(1, 2) = Array("货号", "库存量")
End With
Set d = Nothing
End Sub
|
|