U
UpGrade
Hi.
I have a macro that tests a cell in each sheet of a workbook, then
prints only those sheets that have the right data in that cell. The
problem is that the macro tests a sheet, then prints it, then tests the
next, etc.
I need it to make the tests, compile what sheets need to be printed,
and make a single print job.
I was attempting to use 'worksheets.Array().select' and put the test
data in the array for which sheets to activate for a print session.
I think it might be better to copy the sheets that pass the test to
another (temporary) workbook, and then simple print that entire workbook
to achieve my needed result.
AmI moving in the right direction?
Code follows...
Sub selprint()
Dim i As Integer
Dim currentsheet As Worksheet
For i = 1 To ActiveWorkbook.Worksheets.Count
Set currentsheet = ActiveWorkbook.Worksheets(i)
Worksheets(i).Activate
'Skip empty sheets and hidden sheets
If Application.CountA(currentsheet.Cells) <> 0 And currentsheet.Visible
Then
'change the hard-coded cell here if not F52
If (Not IsNull(Range("F52"))) And (Range("F52").Value <> 0) Then
'un-comment the next line when debugging completed
ActiveSheet.PrintOut
'add comment at start of next line when debugging completed
' ActiveSheet.PrintPreview
End If
End If
Next i
End Sub
I have a macro that tests a cell in each sheet of a workbook, then
prints only those sheets that have the right data in that cell. The
problem is that the macro tests a sheet, then prints it, then tests the
next, etc.
I need it to make the tests, compile what sheets need to be printed,
and make a single print job.
I was attempting to use 'worksheets.Array().select' and put the test
data in the array for which sheets to activate for a print session.
I think it might be better to copy the sheets that pass the test to
another (temporary) workbook, and then simple print that entire workbook
to achieve my needed result.
AmI moving in the right direction?
Code follows...
Sub selprint()
Dim i As Integer
Dim currentsheet As Worksheet
For i = 1 To ActiveWorkbook.Worksheets.Count
Set currentsheet = ActiveWorkbook.Worksheets(i)
Worksheets(i).Activate
'Skip empty sheets and hidden sheets
If Application.CountA(currentsheet.Cells) <> 0 And currentsheet.Visible
Then
'change the hard-coded cell here if not F52
If (Not IsNull(Range("F52"))) And (Range("F52").Value <> 0) Then
'un-comment the next line when debugging completed
ActiveSheet.PrintOut
'add comment at start of next line when debugging completed
' ActiveSheet.PrintPreview
End If
End If
Next i
End Sub