View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Print Command - Array of Worksheets

Maybe like this:

For Each Sh In ActiveWorkbook.Worksheets
If Sh.Visible = True And Sh.Range("G32").Value < "Print"


"mathel" wrote:

I need some help with printing an array of worksheets in a workbook based on
data in a specific cell.

I have a workbook with 11 worksheets within it. Depending on the
information carried forward to the different worksheets, a formula in cell
G32 will indicate 'Print' or remain blank. What I am trying to accomplish is
a macro that will loop through each of the worksheets and print those that
indicate Print in cell G32.

Following is what I tried to accomplish this:

Sub Print_All_Worksheets_With_Value_In_G32()
Dim Sh As Worksheet
Dim Arr() As String
Dim N As Integer
N = 0
For Each Sh In ActiveWorkbook.Worksheets
If Sh.Visible = xlSheetVisible And Sh.Range("G32").Value < "Print"
Then
N = N + 1
ReDim Preserve Arr(1 To N)
Arr(N) = Sh.Name
End If
Next
With ActiveWorkbook
.Worksheets(Arr).PrintOut
End With
End Sub

However, when I try and run this macro, it stops running and the following
line is highlighted:

If Sh.Visible = xlSheetVisible And Sh.Range("G32").Value < "Print"
Then

Any help to correct this problem would be greatly appreciated
--
Linda