+ Reply to Thread
Results 1 to 5 of 5

connecting macros

Hybrid View

  1. #1
    Registered User
    Join Date
    04-15-2009
    Location
    morristown, ny
    MS-Off Ver
    Excel 2007
    Posts
    39

    connecting macros

    JBeaucaire help me with the following code. It works great, I have 14 ranges like this on the same spreadsheet and would like to print all of them based on the result in the target cells for the range of each to print.

    I currently have a macro button to print each range as you can see. Is it possible to connect these? What I have tried is cutting the End Sub and then the Dim r As Long but get errors.


    
    Sub PrintVariedNumber_Products_1and2()
    Dim r As Long
    r = 43 + (Range("E7") * 44) - 44
    
        Range("A1:M" & r).PrintOut copies:=1
            
    
    End Sub
    Sub PrintVariedRange_Products_3and4()
    Dim r As Long
    r = 43 + (Range("S7") * 44) - 44
    
        Range("O1:AA" & r).PrintOut copies:=1
        
        
        
    End Sub
    
    Sub PrintVariedRange_Products_5and6()
    Dim r As Long
    r = 43 + (Range("AG7") * 44) - 44
    
        Range("AC1:AO" & r).PrintOut copies:=1
        
        
        
    End Sub
    Sub PrintVariedRange_Products_7and8()
    Dim r As Long
    r = 43 + (Range("AU7") * 44) - 44
    
        Range("AQ1:BC" & r).PrintOut copies:=1
        
        
        
    End Sub
    Sub PrintVariedRange_Products_9and10()
    Dim r As Long
    r = 43 + (Range("BI7") * 44) - 44
    
        Range("BE1:BQ" & r).PrintOut copies:=1
        
        
        
    End Sub
    Sub PrintVariedRange_Products_11and12()
    Dim r As Long
    r = 43 + (Range("BW7") * 44) - 44
    
        Range("BS1:CE" & r).PrintOut copies:=1
        
        
        
    End Sub
    Sub PrintVariedRange_Products_13and14()
    Dim r As Long
    r = 43 + (Range("CK7") * 44) - 44
    
        Range("CG1:CS" & r).PrintOut copies:=1
        
        
        
    End Sub
    Sub PrintVariedRange_Products_15and16()
    Dim r As Long
    r = 43 + (Range("CY7") * 44) - 44
    
        Range("CU1:DG" & r).PrintOut copies:=1
        
        
        
    End Sub
    Last edited by ed ayers315; 11-09-2009 at 03:47 PM.

  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: connecting macros

    Hi again Ed. Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to edit that post above and put code tags around that code you used. (Like I did below...)

    Sub AllProducts()
    Dim r As Long
    r = 43 + (Range("E7") * 44) - 44
    Range("A1:M" & r).PrintOut copies:=1
    
    r = 43 + (Range("S7") * 44) - 44
    Range("O1:AA" & r).PrintOut copies:=1
    
    r = 43 + (Range("AG7") * 44) - 44
    Range("AC1:AO" & r).PrintOut copies:=1
    
    r = 43 + (Range("AU7") * 44) - 44
    Range("AQ1:BC" & r).PrintOut copies:=1
    
    r = 43 + (Range("BI7") * 44) - 44
    Range("BE1:BQ" & r).PrintOut copies:=1
    
    r = 43 + (Range("BW7") * 44) - 44
    Range("BS1:CE" & r).PrintOut copies:=1
    
    r = 43 + (Range("CK7") * 44) - 44
    Range("CG1:CS" & r).PrintOut copies:=1
    
    r = 43 + (Range("CY7") * 44) - 44
    Range("CU1:DG" & r).PrintOut copies:=1
    
    End Sub
    _________________
    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
    04-15-2009
    Location
    morristown, ny
    MS-Off Ver
    Excel 2007
    Posts
    39

    Re: connecting macros

    Sorry about the code brackets.

    I plugged in your code; trouble with ranges that did not have a target number, the code error'd there.

    Is there a way to jump to the next routine if an error is found?

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

    Re: connecting macros

    You're saying some of the cells might be blank that are supposed to determine how many rows to copy? You'll have to build that test into each section then:

    Sub AllProducts()
    Dim r As Long
    
    If Range("E7") > 0 Then
       r = 43 + (Range("E7") * 44) - 44
       Range("A1:M" & r).PrintOut copies:=1
    End If
    
    etc...

  5. #5
    Registered User
    Join Date
    04-15-2009
    Location
    morristown, ny
    MS-Off Ver
    Excel 2007
    Posts
    39

    Thumbs up Re: connecting macros

    Thanks JB it works great!!!

    Put another in the Solved Column
    Last edited by ed ayers315; 11-09-2009 at 03:44 PM. Reason: Solved

+ 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