本帖最后由 3190496160 于 2023-3-20 16:25 编辑
Sub 采购单()
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
tt = Timer
With Sheets("流水")
r = .Cells(Rows.Count, 3).End(xlUp).Row
ar = .Range("a2:l" & r)
End With
For i = 3 To UBound(ar)
If Trim(ar(i, 11)) = "出库" Then
d(ar(i, 3)) = ""
w = w + 1
End If
Next i
With Sheets("采购单")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs >= 23 Then .Rows("23:" & rs).Delete
.Range("a4:g18") = Empty
If w / 15 = Int(w / 15) Then
sl = w / 15
Else
sl = Int(w / 15) + 1
End If
m = 23
For i = 2 To sl
.Rows("1:22").Copy .Cells(m, 1)
m = m + 22
Next i
m = 2
For Each k In d.keys
n = 0: t = 0
ReDim br(1 To UBound(ar), 1 To 7)
ReDim cr(1 To UBound(ar), 1 To 7)
For i = 3 To UBound(ar)
If Trim(ar(i, 11)) = "出库" Then
If ar(i, 3) = k Then
n = n + 1
If n <= 15 Then
br(n, 1) = n
br(n, 2) = ar(i, 4)
br(n, 3) = ar(i, 8)
br(n, 4) = ar(i, 5)
br(n, 5) = ar(i, 6)
br(n, 6) = ar(i, 7)
br(n, 7) = ar(i, 12)
Else
t = t + 1
cr(t, 1) = n
cr(t, 2) = ar(i, 4)
cr(t, 3) = ar(i, 8)
cr(t, 4) = ar(i, 5)
cr(t, 5) = ar(i, 6)
cr(t, 6) = ar(i, 7)
cr(t, 7) = ar(i, 12)
End If
End If
End If
Next i
.Cells(m, 3) = k
.Cells(m + 2, 1).Resize(15, UBound(br, 2)) = br
If t > 0 Then
m = m + 22
.Cells(m, 3) = k
.Cells(m + 2, 1).Resize(t, UBound(cr, 2)) = cr
End If
m = m + 22
Next k
End With
Application.ScreenUpdating = True
MsgBox "运行完毕,共耗时:" & Format(Timer - tt, "0.00") & "秒"
End Sub
|