|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 生成送货单()
Application.ScreenUpdating = False
Dim ar As Variant
Dim d As Object
Dim rn As Range
Set d = CreateObject("scripting.dictionary")
With Sheets("汇总表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "汇总表为空!": End
ar = .Range("a1:i" & r)
End With
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> Empty Then
d(Trim(ar(i, 1))) = ""
End If
Next i
Set rn = Sheets("模板").Rows("1:41")
With Sheets("送货单")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
.Rows("42:" & rs).Delete
m = 1
For Each k In d.keys
n = 0
ReDim br(1 To UBound(ar), 1 To 8)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) = k Then
n = n + 1
For j = 2 To UBound(ar, 2)
br(n, j - 1) = ar(i, j)
Next j
End If
Next i
If n <= 37 Then
rn.Copy .Cells(m, 1)
.Cells(m + 1, 3) = Left(k, 6)
.Cells(m + 4, 1).Resize(n, UBound(br, 2)) = br
m = m + 41
Else
For i = 1 To n Step 37
rn.Copy .Cells(m, 1)
.Cells(m + 1, 3) = Left(k, 6)
xh = m + 3
For s = i To i + 36 Step 1
If s <= n Then
xh = xh + 1
.Cells(xh, 1).Resize(1, UBound(br, 2)) = Application.Index(br, s, 0)
End If
Next s
m = m + 41
Next i
End If
Next k
End With
Application.ScreenUpdating = True
MsgBox "送货单生成完毕!", 64, "提醒"
End Sub
|
|