Consulting

Results 1 to 6 of 6

Thread: Sleeper: Print Macro Not Working

  1. #1
    VBAX Newbie
    Joined
    Feb 2005
    Posts
    1
    Location

    Question Sleeper: Print Macro Not Working

    Good day,
    I am trying to get an if then statement regarding printing or not printing a page in a spreadsheet to work and I am stuck. Here is the scenario - I have two ranges "Yellow" and "Blue". I want to print both the Yellow and Blue ranges if a particular cell = "yes" and otherwise just print the Yellow range. Here is the coding I am currently trying to use: I created print macros (that do work) called printcombinedsections (to print yellow and blue) and printyellow section (to just print yellow)

    Sub worksheet_Calculate()
    If Range("c25") = "Yes" Then
    printcombinedsections
    Else: PrintYellowSection
    End If
    End Sub
    Any idea would be much appreciated.

    Roofem

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi Roofem, welcome to the board!!


    So this doesn't work for you? Where is this routine located? In what module? And could you not shorten to just ...

    Sub worksheet_Calculate()
        If Range("C25") = "Yes" Then Call printcombinedsections
        Call PrintYellowSection
    End Sub
    You may need to specify the sheet, as it's assuming it's looking at C25 of the ActiveSheet. If this is not the case, tell us what sheet this is on and post the other two codes you have.

    info

  3. #3
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Roofem,

    FYI, this event (I assume it is in the Worksheet code module?):
    
    Sub worksheet_Calculate()
    Will only fire when the worksheet is recalculated (you press F9 or change a number that forces calculation.)

    Are you sure this is the way you want to trigger the code?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Zack,
    Looks to me like your code will print the Yellow section twice!
    MD

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by mdmackillop
    Hi Zack,
    Looks to me like your code will print the Yellow section twice!
    MD
    Could, yes. If code like mine were to be used, I'd say to take out printing the "yellow" range from the first routine. This just seems that there is a better way to do these things. That's why I asked to see the entire code.

    Thanks Malcolm! You shall hence forth be known to me as Eagle-Eye.

  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Hi roofem,

    Your code should work if "printcombinedsections" and "PrintYellowSection" are in the same sheet module you're using the Sheet_Calculate in, or if they're in another ordinary "bas" module, but it wont work if they're in another sheet module or in 'ThisWorkbook' module.

    You could then try Call printcombinedsections or, Run ("printcombinedsections") but it's best to try to avoid using code in one sheet module to run code on another sheet module - use a basic module...

    HTH,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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