excel vba中的两个代码合一,要求查询不到记录的时候不打印并且把错误的编号记下来到最后提示出来!
Sub 连续打印()Dim i
i = 16
For i = 16 To 30
If Cells(i, 2) = "" Then
MsgBox "================亲,批量打印完成!=================="
Exit Sub
End If
Cells(2, 5) = Cells(i, 2)
Call 查找内容省窗
ThisWorkbook.PrintPreview
Next
End Sub
Sub 查找内容省窗()
With Sheets("记录汇总")
lastrow = .Cells(10000, 1).End(xlUp).Row
Rng = .Range("a2:b" & lastrow)
For i = 1 To UBound(Rng)
If Rng(i, 1) = Cells(2, 5) Then
rng1 = .Range(.Cells(i + 1, 2), .Cells(i + 1, 62))
Range("e3").Resize(61, 1) = Application.Transpose(rng1)
' MsgBox "查询成功!"
Range("E53").Select
Selection.Copy
Range("F7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("E54").Select
Selection.Copy
Range("F20").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
'MsgBox "===============查询成功!================"
Exit Sub
End If
Next
End With
MsgBox ("=========不好意思,没有查到此ID的相关记录===========!")
End Sub