Use range to determine which workbooks to print together with .PrintOut

Lightkeepr

New Member
Joined
Apr 6, 2021
Messages
27
Office Version
  1. 365
Platform
  1. Windows
I have nine worksheets in a file as follows:
SETUP (never printed out)
DATA (never printed out)
POT (never printed out)
PCR
PCOST
JSUM
PRA
DELTA
CSR

On sheet DATA in cells F174:K174 i have formulas that if the worksheet is to be printed the cell will have the sheets name visible. Using VBA, how would I get the sheet names that are visible in that cell range (ignoring the blank or "" cells) and pass them to the .PrintOut as the sheets to be printed together as one document?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Lightkeeper,

I hope my assumption is correct that the cells are not being formatted to be "invisible" using the custom format ";;;" and are rather some type of IF statement formula displays the name of the sheet or a blank, depending on a condition set, such as =IF(F2=1, "Sheet1", "")

Try this out:

VBA Code:
Sub printSheets()
    Dim ws      As Worksheet
    Dim printWS As Worksheet
    
    Set ws = Application.ThisWorkbook.Worksheets("DATA")
    
    For i = 6 To 11
        If ws.Cells(174, i) <> "" Then
            Set printWS = Application.ThisWorkbook.Worksheets(ws.Cells(174, i).Value)
            printWS.PrintOut
        End If
    Next i
End Sub
 
Upvote 0
Solution
I was using range to tell the VBA where the cells on row 174 were and your solution did it! Thank you for the help, I appreciate it!
 
Upvote 0
Hi Lightkeeper,

I hope my assumption is correct that the cells are not being formatted to be "invisible" using the custom format ";;;" and are rather some type of IF statement formula displays the name of the sheet or a blank, depending on a condition set, such as =IF(F2=1, "Sheet1", "")

Try this out:

VBA Code:
Sub printSheets()
    Dim ws      As Worksheet
    Dim printWS As Worksheet
   
    Set ws = Application.ThisWorkbook.Worksheets("DATA")
   
    For i = 6 To 11
        If ws.Cells(174, i) <> "" Then
            Set printWS = Application.ThisWorkbook.Worksheets(ws.Cells(174, i).Value)
            printWS.PrintOut
        End If
    Next i
End Sub

Is there a way with this setup to have them print out as one document instead of all individuals?
 
Upvote 0
You can use something like:

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).PrintOut, I think. You'd just have to develop a bit of code to determine which sheets need to go into the array.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,575
Members
449,039
Latest member
Arbind kumar

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