View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Print function parsing help

UpGrade,

Change "Correct Value" to the, not surprisingly, correct value....


Sub UpGradePrintJob()
Dim Sel As Boolean
Dim myS As Worksheet

Sel = True

For Each myS In Worksheets
If myS.Visible Then
If myS.Range("F52").Value = "Correct Value" Then
myS.Select Sel
Sel = False
End If
End If
Next myS

ActiveWindow.SelectedSheets.PrintOut

End Sub


HTH,
Bernie
MS Excel MVP


"UpGrade" wrote in message
...


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