标题:excel vba中的两个代码合一,要求查询不到记录的时候不打印并且把错误的编号 ...
取消只看楼主
zhaoyin
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2022-1-19
结帖率:60%
已结贴  问题点数:5 回复次数:2 
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
搜索更多相关主题的帖子: 打印 Select End 记录 Sub 
2022-01-20 20:45
zhaoyin
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2022-1-19
得分:0 
我自己现在搞成这样了,后面请大神看看怎么显示查不到的单号!
Sub 连续打印()
Dim b, x
x = 16
b = 15
Do While b <= 30
   b = b + 1
    If Cells(b, 2) = "" Then
        
        
        If b - x > 0 Then
             MsgBox "有" & b - x & "个单号不正确,没有打印"
             Exit Sub
        End If
   
   
           MsgBox "=====亲,批量打印完成!共批量打印" & b - 16 & "张生产单====="
           Exit Sub
    End If
  Cells(2, 5) = Cells(b, 2)
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
    x = x + 1
       'MsgBox "===============查询成功!================"
       ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False '快速打印
  
       'ThisWorkbook.PrintPreview '预览打印,选择打印机。
      Exit For

End If
Next  
End With

Loop

End Sub
2022-02-14 20:28
zhaoyin
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2022-1-19
得分:0 
回复 2楼 独木星空
我自己搞成上面那样,你帮我看看要怎么完善?
2022-02-14 20:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-508201-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031702 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved