|
本帖最后由 吴中泉 于 2023-5-17 19:01 编辑
Sub ssjss() '//2023.5.17
Dim arr, brr, d, T
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set d = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
Dim tm: tm = Timer
brr = [{"入库表","出库表"}]
For x = 1 To 2
arr = Sheets(brr(x)).UsedRange.Value
For i = 2 To UBound(arr)
yf = Month(arr(i, 3)) 'yf月份
rq = Day(arr(i, 3)) 'rq日期
T = arr(i, 9) & "|" & arr(i, 2) & "|" & yf & "|" & rq
d(T) = d(T) + arr(i, 13) 'T不同的字典键值
d2(arr(i, 9) & "-" & yf) = yf
Next
Next
For Each sht In Sheets '遍历12个月
If Val(sht.Name) Then
With sht
yf = Val(.Name)
.UsedRange.Offset(1).Clear
i = 2
For Each bh In d2.keys 'bh商品编号+月份
If yf = d2(bh) Then
i = i + 1
.Cells(i, 1) = Split(bh, "-")(0) '生成当月的不重复商品编号
End If
Next
arr = .UsedRange.Value
For i = 2 To UBound(arr)
T = arr(i, 1)
If T <> Empty Then
For j = 6 To UBound(arr, 2)
If arr(1, j) = Empty Then Exit For
kb = Right(Trim(arr(1, j)), 2) 'kb库别
rq = Val(arr(1, j)) 'rq日期
T = arr(i, 1) & "|" & kb & "|" & yf & "|" & rq
If d.exists(T) Then
arr(i, j) = d(T)
If kb = "入库" Then
arr(i, 3) = arr(i, 3) + arr(i, j) '入库数量
Else
arr(i, 4) = arr(i, 4) + arr(i, j) '出库数量
End If
End If
Next
arr(i, 2) = d2(arr(i, 1)) '上、上月库存
arr(i, 5) = arr(i, 2) + arr(i, 3) - arr(i, 4) '本月库存
d2(arr(i, 1)) = arr(i, 5) '库存结转
End If
Next
.UsedRange.Value = arr
End With
End If
Next
Application.ScreenUpdating = True
MsgBox "共用时:" & Format(Timer - tm, "0.0秒")
End Sub
|
|