Print based on a cell contents

EdGilmore

New Member
Joined
Mar 25, 2011
Messages
12
I have a workbook set up that I would like to run a macro for to print a selection of sheets based on the text input into a cell. The worksheets are labeled:

Details
NFP1
NFP2

There are other sheets in the workbook, but these are not required to be printed.

So, if cell k21 on "details" contains the phrase "NFP1 and NFP2", I want all 3 sheets to print.

If k21 contains "NFP1 and Exit", I want to print "details", "NFP1" and then link to a seperate workbook entitled PLP for which I currently have a seperate macro set up:

Sub Open_exit()
'
' Open_exit Macro
'

'
ChDir "H:\"
Workbooks.Open Filename:="H:\PLP1.xls"
End Sub

If k21 is blank, I want the print function to become defunct.

Please help!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This should get you started.... write back if problems,,, (though I'm not going to be available for the rest of the evening...................

Code:
Sub Foo()
Dim MyWks
On Error Resume Next
MyWks = Array("Details", "NFP1", "NFP2")
Status = Worksheets("Details").Range("K21").Value
Select Case Status
Case "NFP1 and NFP2"
    Sheets("Details").Activate
    ActiveSheet.PrintPreview
    Sheets("NFP1").Activate
    ActiveSheet.PrintPreview
    Sheets("NFP2").Activate
    ActiveSheet.PrintPreview

Case "NFP1 and Exit"
    Sheets("Details").Activate
    ActiveSheet.PrintPreview
    Sheets("NFP1").Activate
    ActiveSheet.PrintPreview
    Workbooks.Open Filename:="H:\PLP1.xls"
Case ""
    Exit Sub
End Select
End Sub
 
Upvote 0
I have a similar situation and am trying to make this solution work but I have one minor difference that has me hung up.

Rather than having a single cell reference to take into account, I actually need to evaluate the contents of 6 difference cells in my primary worksheet.

Each of these cells corresponds to another sheet that contains more detailed information related to that cell. I want to print the primary worksheet and the sheet associated with each of the evaluated cells where the cell value is greater than zero. For each evaluated cell that has a zero value, I want to skip printing the associated sheet.

Can you help point me in the right direction?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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