Print page problem

sthack99

Board Regular
Joined
May 16, 2006
Messages
237
Can anyone tell me what I'm doing wrong? I'm trying to set it to if every cell in the 1st range is blank, then only print page 3; if every cell in the 2nd range is blank, then only print page 4; if neither range is completely blank, then print both sheets.

Sub Button11_Click()
'
' Button11_Click Macro
' Macro recorded 7/24/2007 by Sara Thackston
'

Dim rngP As Range
Dim rngG As Range

Set rngP = Sheets("AP TEMP").Range("I2:I15,L2:L15").Value
Set rngG = Sheets("AP TEMP").Range("I18:I25,L18:L25").Value

If rngG = "" Then
ActiveWindow.SelectedSheets.PrintOut From:=3, To:=3, Copies:=Range("N36").Value, Collate _
:=True
Exit Sub
End If
If rngP = "" Then
ActiveWindow.SelectedSheets.PrintOut From:=4, To:=4, Copies:=Range("N36").Value, Collate _
:=True
Exit Sub
End If
ActiveWindow.SelectedSheets.PrintOut From:=3, To:=4, Copies:=Range("N36").Value, Collate _
:=True
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Try this:


Sub myPrnt()
'Standard module code, like: Module1.
Dim rngP As Object, rngG As Object, cell As Object
Dim booMyFlg1 As Boolean, booMyFlg2 As Boolean
Dim lngG&, lngP&

Set rngP = Sheets("Sheet1").Range("I2:I15", "L2:L15")
Set rngG = Sheets("Sheet1").Range("I18:I25", "L18:L25")

For Each cell In rngG
If cell.Value = "" Then lngG = lngG + 1
Next cell

If lngG = rngG.Count Then booMyFlg1 = True

If booMyFlg1 = True Then
ActiveWindow.SelectedSheets.PrintOut From:=3, To:=3, Copies:=Range("N36").Value, Collate _
:=True
Exit Sub
End If

For Each cell In rngP
If cell.Value = "" Then lngP = lngP + 1
Next cell

If lngP = rngP.Count Then booMyFlg2 = True

If booMyFlg2 = True Then
ActiveWindow.SelectedSheets.PrintOut From:=4, To:=4, Copies:=Range("N36").Value, Collate _
:=True
Exit Sub
End If

ActiveWindow.SelectedSheets.PrintOut From:=3, To:=4, Copies:=Range("N36").Value, Collate _
:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,190,883
Messages
5,983,387
Members
439,841
Latest member
goodwillhunting

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top