|
原代码中主要是出现了“打印表”这个表不存在的问题导致
- Sub test()
- Dim wPrn As Worksheet, wSH As Worksheet, rRNG As Range
- Dim vData As Variant, nRow As Double, nCol As Integer
- Dim vPrn As Variant, nPrn As Double
-
- On Error Resume Next
- Set wPrn = Sheets("打印表")
- If Err.Number = 0 Then
- wPrn.Select
- Else
- Set wPrn = Sheets.Add(after:=Sheets(Sheets.Count))
- wPrn.Name = "打印表"
- End If
- On Error GoTo 0
-
- For Each wSH In Sheets
- With wSH
- If .Name <> "打印表" Then
- Set rRNG = Nothing
- Set rRNG = .[J:J].Find(what:="Y", LookAt:=xlWhole)
- If Not rRNG Is Nothing Then
- vData = .[A1:J1].Resize(.Cells(.Rows.Count, 1).End(xlUp).Row)
- ReDim vPrn(1 To 10, 1 To 11)
- nPrn = 0
- For nRow = 1 To UBound(vData)
- If vData(nRow, 10) = "Y" Then
- nPrn = nPrn + 1
- ReDim Preserve vPrn(1 To 10, 1 To nPrn)
- For nCol = 1 To 10
- vPrn(nCol, nPrn) = vData(nRow, nCol)
- Next
- End If
- Next
- If nPrn > 0 Then
- With wPrn
- .UsedRange.ClearContents
- .[A1].Resize(nPrn, 10) = vPrn
- .PrintPreview
- End With
- End If
- End If
- End If
- End With
- Next
- End Sub
复制代码 |
|