Combining Print Areas

tbeards

New Member
Joined
May 27, 2009
Messages
47
Happy Friday Excel Wizards!

There are similar posts on the boards but I haven't found one that quite gets me to where I need to be and I am getting desperate! What I want to do is have a userform that includes checkboxes and upon selection of the checkbox, it will print the quote for the particular fruit or fruits selected. The Quote template is on one tab in the workbook where cells A1:S60 contain the quote for Oranges, cells A68:S128 contain the quote for Apples, cells A129:S189 contain the quote for Watermellon, etc. going down for all six fruits...

What I want my code to do is to set the print range based on the fruits selected so if the user picks Oranges and Watermelons, it won't set the print area for Apples. Each quote is a named range so cells A1:S60 is named Quote_Oranges_Print_Area".

The following code works but as you can probably guess where I am going, there are 36 different combinations of print areas based on whether the user selects one fruit or a combination. I do not want to enter in all of the combinations nor put a lookup table in the worksheet (matrix based on true/false values) and instead am looking for code to set the print area.


Code:
Private Sub cmdTestPrintArea_Button_Click()
'************* put in the code here to select the print areas for the quotes ****************
If frmQuote.chkQuoteOranges.Value = True And frmQuote.chkQuoteApples.Value = False And _
frmQuote.chkQuoteWatermelon.Value = False And frmQuote.chkQuoteCherries.Value = True And _
frmQuote.chkQuotePapaya.Value = True And frmQuote.chkQuoteGrapes.Value = False Then
 
ActiveSheet.PageSetup.PrintArea = "Quote_Oranges_Print_Area,Quote_Cherries_Print_Area,Quote_Papaya_Print_Area,Quote_Grapes_Print_Area,"
 
End Sub
 
*** I am thinking I could do this with either a select case or an If Then such as the code below but it doesn't work
 
If frmQuote.chkQuoteOranges.Value = True Then 
strOrangePrintArea = ThisWorkbook.Names("Quote_Oranges_Print_Area") Else
""
End If
 
If frmQuote.chkQuoteApples.Value = True Then 
strApplesPrintArea = ThisWorkbook.Names("Quote_Apples_Print_Area") Else
""
End If
 
If frmQuote.chkQuoteWatermelon.Value = True Then 
strWatermelonPrintArea = ThisWorkbook.Names("Quote_Watermelon_Print_Area") Else
""
End If
 
'***** and the same for the rest of the fruit ******
'***** then *****
 
ActiveSheet.PageSetup.PrintArea = strOrangePrintArea & strApplesPrintArea & strWatermelonPrintArea

Any ideas???? Thank you beforehand
 
Last edited by a moderator:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I made a typo in my code and this line:

ActiveSheet.PageSetup.PrintArea = "Quote_Oranges_Print_Area,Quote_Cherries_Print_Area,Quote_Papaya_Print_Area,Quote_Grapes_Print_Area,"

should be
ActiveSheet.PageSetup.PrintArea = "Quote_Oranges_Print_Area,Quote_Cherries_Print_Area,Quote_Papaya_Print_Area"
 
Upvote 0
I am not sure how to edit my original thread; however, I don't think my example was very clean in my original thread so I am pasting the cleaned up code that works but I don't want 56 different combinations, just one. Any ideas? My code works and I think I have all of the combinations but it is long and I would like to shorten the code since I may include quotes for other countries besides the US.

Sub SetQuotePrintAreaFruit()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
Sheets(constSheetUSQuote).Activate<o:p></o:p>
<o:p></o:p>
'************** Clear Print Area **************
ActiveSheet.PageSetup.PrintArea = ""<o:p></o:p>
<o:p></o:p>
'**************************************************<o:p></o:p>
'********* Select the print areas for the quotes *************
'**************************************************
<o:p></o:p>
'Scenario #1 <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:City w:st="on"><st1:place w:st="on">Oranges</st1:place></st1:City>,Apples,Watermelon,Cherries,Grapes,Papaya<o:p></o:p>
If frmQuote.chkQuoteOranges.Value = True And frmQuote.chkQuoteApples.Value = True And _<o:p></o:p>
frmQuote.chkQuoteWatermelon.Value = True And frmQuote.chkQuoteGrapes.Value = True And _<o:p></o:p>
frmQuote.chkQuoteCherries.Value = True And frmQuote.chkQuotePapaya.Value = True Then
<o:p></o:p>
ActiveSheet.PageSetup.PrintArea = "Quote_Oranges_Print_Area,Quote_Apples_Print_Area,Quote_Watermelon_Print_Area,Quote_Cherries_Print_Area,Quote_Papaya_Print_Area,Quote_Grapes_Print_Area"<o:p></o:p>

Else<o:p></o:p>
<o:p></o:p>
'Scenario #2 <st1:City w:st="on"><st1:place w:st="on">Oranges</st1:place></st1:City>,Apples,Grapes<o:p></o:p>
If frmQuote.chkQuoteOranges.Value = True And frmQuote.chkQuoteApples.Value = False And _<o:p></o:p>
frmQuote.chkQuoteWatermelon.Value = False And frmQuote.chkQuoteGrapes.Value = True And _<o:p></o:p>
frmQuote.chkQuoteCherries.Value = False And frmQuote.chkQuotePapaya.Value = False Then<o:p></o:p>

ActiveSheet.PageSetup.PrintArea = "Quote_Oranges_Print_Area,Quote_Grapes_Print_Area"<o:p></o:p>

Else<o:p></o:p>
<o:p></o:p>
'************** And so on for Scenarios #3 to #55 *************<o:p></o:p>
<o:p></o:p>
'Scenario #56 Cherries,Papaya<o:p></o:p>
If frmQuote.chkQuoteOranges.Value = False And frmQuote.chkQuoteApples.Value = True And _<o:p></o:p>
frmQuote.chkQuoteWatermelon.Value = False And frmQuote.chkQuoteGrapes.Value = False And _<o:p></o:p>
frmQuote.chkQuoteCherries.Value = True And frmQuote.chkQuotePapaya.Value = False Then<o:p></o:p>
ActiveSheet.PageSetup.PrintArea = "Quote_Cherries_Print_Area,Quote_Papaya_Print_Area"<o:p></o:p>
Else<o:p></o:p>
<o:p></o:p>
Call MsgBox("This Quote Combination isn't set up for printing, contact your administrator to have added", vbOKOnly)<o:p></o:p>
<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
<o:p>'*********** And I have all of the End Ifs for the other scenarios ******* </o:p>

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

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