|
Sub 统计库存()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("B表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "B表为空!": End
ar = .Range(.Cells(4, 1), .Cells(r, 4))
End With
y = 2
k = 1
ReDim br(1 To UBound(ar), 1 To 500)
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
t = d(ar(i, 1))
If t = "" Then
k = k + 1
d(ar(i, 1)) = k
t = k
br(k, 1) = ar(i, 1)
br(k, 2) = ar(i, 2)
End If
lh = d(ar(i, 3))
If lh = "" Then
y = y + 1
d(ar(i, 3)) = y
lh = y
br(1, y) = ar(i, 3)
End If
br(t, lh) = br(t, lh) + ar(i, 4)
End If
Next i
With Sheets("A表")
.[a1].CurrentRegion.Borders.LineStyle = 0
.[a1].CurrentRegion = Empty
.[a1].Resize(k, y) = br
.[a1].Resize(k, y).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|