+ Reply to Thread
Results 1 to 7 of 7

VBA - Print Worksheets Based on Cell Value

  1. #1
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    VBA - Print Worksheets Based on Cell Value

    I have a workbook where I want it to print worksheets based on cell value. I always want the main worksheet (called Template) to print. I also want the worksheet associated with the value in cell A1:J1 (merged cell) to print. I thought I had the code right, or pretty close, but it doesn't seem to be working.

    Please Login or Register  to view this content.
    Is there something I'm missing here? Also, I want the Print Options pop-up box to appear as we sometimes need to change things there.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA - Print Worksheets Based on Cell Value

    This should be all you need to print:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-18-2012 at 01:43 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: VBA - Print Worksheets Based on Cell Value

    That's not working either. Is it missing the command to print after it selects the worksheets?

  4. #4
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: VBA - Print Worksheets Based on Cell Value

    thesonofdarwin,

    Try this:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA - Print Worksheets Based on Cell Value

    you said you wanted to printout but have the print dialog open. My macro does that... it selects the two sheets and opens the print dialog.
    Please Login or Register  to view this content.

    If all you want is for it to print the sheets for you, just change that to:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-13-2009
    Location
    PA
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: VBA - Print Worksheets Based on Cell Value

    Alright, that works if I activate it as a Macro. I know there is a way to activate this automatically just by hitting hitting print as I've accomplished it previously, but I cannot find my code.

    I'm sorry, I was not clear about my goal. I want the user to be able to click Print (Quick Print or File->Print) and for this to work.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA - Print Worksheets Based on Cell Value

    You can try putting that into a Workbook_BeforePrint event macro in the ThisWorkbook module, but I wouldn't recommend that. Since the default hotkey for printing is CTRL-P, for this workbook I would install the macro as shown, then assign the CTRL-P hotkey to that macro. Then you can still access the normal print dialog using the FILE > PRINT method.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1