|
楼主 |
发表于 2024-5-11 17:57
|
显示全部楼层
Sub test()
Dim r%, i%
Dim arr, brr
Dim ws As Worksheet
Dim d As Object
Set d = CreateObject("scripting.dictionary")
m = 0
For Each ws In Worksheets
If ws.Name Like "#*" Then
With ws
r = .Cells(.Rows.Count, 2).End(xlUp).Row
If r > 1 Then
arr = .Range("a2:d" & r)
For i = 1 To UBound(arr)
If Not d.exists(arr(i, 2)) Then
m = m + 1
ReDim brr(1 To 4)
brr(1) = m
brr(2) = arr(i, 2)
brr(3) = arr(i, 3)
Else
brr = d(arr(i, 2))
End If
brr(4) = brr(4) + arr(i, 4)
d(arr(i, 2)) = brr
Next
End If
End With
End If
Next
With Worksheets("库存")
.UsedRange.Offset(1, 0).Clear
.Range("a2").Resize(d.Count, UBound(brr)) = Application.Transpose(Application.Transpose(d.items))
End With
End Sub |
|