|
楼主 |
发表于 2024-6-29 07:58
|
显示全部楼层
本帖最后由 kdsea 于 2024-6-29 10:47 编辑
Sub 库存()
Range("A2:P10000").Clear
arr = Sheets("5月底库").UsedRange
brr = Sheets("入库").UsedRange
crr = Sheets("出库").Range("A1").CurrentRegion
Dim drr(1 To 1000, 1 To 5)
'--------------------------------- 期初
Set d = CreateObject("scripting.dictionary")
h = 1
For i = 2 To UBound(arr)
drr(h, 2) = arr(i, 1)
drr(h, 3) = arr(i, 2)
h = h + 1
Next
Range("A2").Resize(h - 2, 5) = drr
Erase drr
Set d = Nothing
Set d = CreateObject("scripting.dictionary")
LW = Cells(Rows.Count, "B").End(xlUp).Row + 1
'--------------------------------- 入库
For i = 2 To UBound(brr)
If d.Exists(brr(i, 4)) Then
h = d(brr(i, 4))
drr(h, 2) = brr(i, 4)
drr(h, 4) = drr(h, 4) + brr(i, 7)
Else
k = k + 1
d(brr(i, 4)) = k
' drr(k, 1) = brr(i, 1)
drr(k, 2) = brr(i, 4)
drr(k, 4) = brr(i, 7)
End If
Next
Range("A" & LW).Resize(k, 5) = drr
LW = Cells(Rows.Count, "B").End(xlUp).Row + 1
Erase drr
Set d = Nothing
Set d = CreateObject("scripting.dictionary")
k = 0: h = 0
'--------------------------------- 出库
For i = 2 To UBound(crr)
If d.Exists(crr(i, 2)) Then
h = d(crr(i, 2))
drr(h, 5) = drr(h, 5) + crr(i, 3)
Else
k = k + 1
d(crr(i, 2)) = k
' drr(k, 1) = brr(i, 1)
drr(k, 2) = crr(i, 2)
drr(k, 5) = crr(i, 3)
End If
Next
Range("A" & LW).Resize(k, 5) = drr
Columns(1).Delete
k = 0: h = 0
Stop
'===========================================合并
Set d = Nothing
Set d = CreateObject("scripting.dictionary")
Dim Br(1 To 10000, 1 To 5)
Ar = Range("A1").CurrentRegion
On Error Resume Next
For i = 1 To UBound(Ar)
If d.Exists(Ar(i, 1)) Then
h = d(Ar(i, 1))
Br(h, 2) = Br(h, 2) + Ar(i, 2)
Br(h, 3) = Br(h, 3) + Ar(i, 3)
Br(h, 4) = Br(h, 4) + Ar(i, 4)
Else
k = k + 1
d(Ar(i, 1)) = k
' drr(k, 1) = brr(i, 1)
Br(k, 1) = Ar(i, 1)
Br(k, 2) = Ar(i, 2)
Br(k, 3) = Ar(i, 3)
Br(k, 4) = Ar(i, 4)
End If
Next
Range("A2:M10000").Clear
Range("A1").Resize(k, 5) = Br
[A1:E1] = Array("煤种", "期初库存", "入库", "出库", "结存")
End Sub
|
|