New to VBA - vba if a cell contains certain text then print that specific page

JDSOuth49

New Member
Joined
Feb 16, 2024
Messages
46
Office Version
  1. 365
Platform
  1. Windows
My Excel document contains 6 pages which are broken by page breaks.

The first 3 pages will always need to print, but pages 4, 5, and 6 only need to print if the there is text input into a specific cell:
IF D122 >0, THEN PRINT PAGES 1 THROUGH 4
IF D166 >0, THEN PRINT PAGES 1 THROUGH 5
IF D210 >0, THEN PRINT PAGES 1 THROUGH 6

Any help would be greatly appreciated.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this macro:
VBA Code:
Public Sub Print_Specific_Pages()

    With ActiveSheet
        If .Range("D122").Value > 0 Then
            .PrintOut From:=1, To:=4
        ElseIf .Range("D166").Value > 0 Then
            .PrintOut From:=1, To:=5
        ElseIf .Range("D210").Value > 0 Then
            .PrintOut From:=1, To:=6
        Else
            .PrintOut From:=1, To:=3
        End If
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

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