|
Sub 台账()
Application.ScreenUpdating = False
Dim ar As Variant
Dim i As Long, r As Long, rs As Long
Dim br()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("出库底单")
r = .Cells.Find("*", searchdirection:=xlPrevious).Row
y = .Cells(4, Columns.Count).End(xlToLeft).Column
If r < 5 Then MsgBox "出库底单工作表为空!": End
ar = .Range(.Cells(2, 1), .Cells(r, y))
End With
For j = 4 To UBound(ar, 2) - 3 Step 4
If ar(1, j - 3) <> "" Then
For i = 3 To UBound(ar)
If ar(i, j) <> "" Then
s = ar(1, j - 3) & "|" & ar(i, j)
If Not d.exists(s) Then Set d(s) = CreateObject("scripting.dictionary")
dc(s) = j
d(s)(i) = ""
End If
Next i
End If
Next j
rr = Array("大米", "菜油", "辣椒", "盐巴")
With Sheets("营养餐出库台账")
With .UsedRange.Offset(4)
.ClearContents
.UnMerge
.Borders.LineStyle = 0
End With
rs = 1
For Each k In d.keys
n = 0: w = w + 1
ReDim br(1 To d(k).Count + 4, 1 To 9)
lh = dc(k)
For Each kk In d(k).keys
n = n + 1
br(n, 1) = n
br(n, 2) = ar(kk, lh - 3)
br(n, 5) = ar(kk, lh - 2)
br(n, 6) = ar(kk, lh - 1)
br(n, 8) = "仟山农户产品运营有限公司"
rq = ar(1, lh - 3)
cb = ar(kk, lh)
Next kk
For i = 0 To UBound(rr)
n = n + 1
br(n, 1) = n
br(n, 2) = rr(i)
If rr(i) = "盐巴" Then
br(n, 5) = "包"
Else
br(n, 5) = "斤"
End If
br(n, 8) = "仟山农户产品运营有限公司"
Next i
If w = 1 Then GoTo 10
.Rows("1:4").Copy .Cells(rs, 1)
10:
.Cells(rs + 1, 2) = rq
.Cells(rs, 1) = "2024年秋季学生营养改善计划食品出库台账(" & cb & ")"
.Cells(rs + 4, 1).Resize(n, UBound(br, 2)) = br
.Cells(rs + 4, 1).Resize(20, 15).Borders.LineStyle = 1
.Rows(rs & ":" & rs + 23).RowHeight = 21
rs = rs + 24
Next k
End With
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|