|
为解决打印的页数问题,经一晚的思考,调试成功,最后一段打印的代码作了调整
Sub 领料单打印()
' https://club.excelhome.net/threa ... tml?_dsign=68639f0d
' 2024-4-18
Sheet6.Select
Range("A6:G15").ClearContents
'-----
c_dh = Sheet6.Cells(3, 6).Value
If IsEmpty(c_dh) Then
MsgBox "单据号不能为空!!!"
Exit Sub
End If
'------
x5 = 2
foun = False
sn = 0
Do While Not (IsEmpty(Sheet5.Cells(x5, 1).Value))
If Sheet5.Cells(x5, 1).Value = c_dh Then
sn = sn + 1
foun = True
If sn = 1 Then
Sheet6.Cells(3, 2).Value = Sheet5.Cells(x5, 2).Value
Sheet6.Cells(4, 2).Value = Sheet5.Cells(x5, 3).Value
Sheet6.Cells(4, 6).Value = Sheet5.Cells(x5, 4).Value
Sheet6.Cells(17, 2).Value = Sheet5.Cells(x5, 12).Value
Sheet6.Cells(17, 4).Value = Sheet5.Cells(x5, 13).Value
Sheet6.Cells(17, 6).Value = "领料人:" & Sheet5.Cells(x5, 14).Value
End If
End If
x5 = x5 + 1
Loop
If foun = False Then
MsgBox "请正确输入单据号!!!"
Exit Sub
End If
'------
x5 = 2
x1 = 1
Do While Not (IsEmpty(Sheet5.Cells(x5, 1).Value))
If Sheet5.Cells(x5, 1).Value = c_dh Then
For y = 1 To 14
Sheet1.Cells(x1, y).Value = Sheet5.Cells(x5, y).Value
Next y
x1 = x1 + 1
End If
x5 = x5 + 1
Loop
'--完成数据转移到“开单过渡表”上
i = 0
For x = 1 To sn
i = i + 1
For y = 1 To 7
Sheet6.Cells(i + 5, y).Value = Sheet1.Cells(x, y + 4).Value
Next y
If i = 9 Then ‘ 写满9行就进行打印
'ActiveWindow.SelectedSheets.PrintOut ' 不预览,直接打印
ActiveWindow.SelectedSheets.PrintPreview ' 预览,人控打印
Range("A6:G15").ClearContents
i = 0
End If
Next x
If Int(sn / 9) <> sn / 9 Then ' 最后一张不足9人,前面的IF是不打印的,此处打印
ActiveWindow.SelectedSheets.PrintPreview ' 预览,人控打印 尾数不满的页
Range("A6:G15").ClearContents
End If
End Sub
实现了 逢9打印,页数不受限制 |
|