If/Then Print Selected Page

chelseasikoebs

Board Regular
Joined
Mar 9, 2009
Messages
61
I thought this would be really easy, but it's not working. I wanted it to look at a cell on page 1 and if it's empty, do nothing, but if it has content in it, print page 1, then go on to page 2 and do the same thing all the way through to page 6. But I can't even get page 1 to work!

Code:
Sub PrintPurchLogs()

Dim x As Range
For Each x In Range("D10")
    If IsEmpty(x) Then
        'do nothing
    Else
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate:=False, IgnorePrintAreas:=False
    End If
        
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You can add a "Next x" line at the bottom or your code, or do it all in a single line like this:
Code:
Sub PrintPurchLogs2()
    If Range("D10").Value <> "" Then ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate:=False, IgnorePrintAreas:=False
End Sub
 
Upvote 0
Okay. I see. I forgot the Next. I like yours better, though. Thank you! Now, if I want it to then look at cell D62, I just repeat the code but replace D10 with D62? or do I need Then If or something like that?

Code:
Sub PrintPurchLogs2()     If Range("D10").Value <> "" Then ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate:=False, IgnorePrintAreas:=False
    If Range("D62").Value <> "" Then ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate:=False, IgnorePrintAreas:=False End Sub
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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
Back
Top