+ Reply to Thread
Results 1 to 8 of 8

Apply Macro to a number of sheets

  1. #1
    Registered User
    Join Date
    08-09-2011
    Location
    Colorado Spgs, USA
    MS-Off Ver
    Excel 2008
    Posts
    34

    Apply Macro to a number of sheets

    Hi guys I have these two Macros that will print two ranges from a sheet on two different sheets. :

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I need to apply this code to Sheets named "10" all the way to "360" so I just run the macros and it will print these ranges from all the sheets

    Also if you have any suggestions on how to turn the 2 macros into one that would be great too!
    Please help!!
    Thanks

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Apply Macro to a number of sheets

    Hi
    are your sheets actually named 10 to 360, or are these just the numbers?

    if names, try the macro below
    if numbers, cut the bit sn = "" & n & "", and use sheets(n).select not sheets(sn).select

    Please Login or Register  to view this content.

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

    Re: Apply Macro to a number of sheets

    Without actually needing to "select" the individual sheets:

    Please Login or Register  to view this content.
    _________________
    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!)

  4. #4
    Registered User
    Join Date
    08-09-2011
    Location
    Colorado Spgs, USA
    MS-Off Ver
    Excel 2008
    Posts
    34

    Re: Apply Macro to a number of sheets

    It worked well for the first sheet, then it stops and tells me "Subscript out of range" Yes, my sheets are named numerically, but I just realized that there is no pattern to them, so they are NOT named 10, 11,12, 13 etc but something like 10,20,40,60,80,120. Is there anyway to print the only the sheets that are named numerically cause I have other tabs in there that I dont need to print!

    Thank you so much!

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Apply Macro to a number of sheets

    try this:

    Please Login or Register  to view this content.

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

    Re: Apply Macro to a number of sheets

    Again, no need to "select" things in VBA to run code on them, usually. Adjust the "array" to list the sheet names:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-09-2011
    Location
    Colorado Spgs, USA
    MS-Off Ver
    Excel 2008
    Posts
    34

    Re: Apply Macro to a number of sheets

    Hi,
    The last one almost worked. I need to print Column B with range 1 on one page as well as range 2 on another page. It does that in some in others it doesn't. The one before last again gave me subscript out of range.

    Thanks for all your help

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

    Re: Apply Macro to a number of sheets

    Subscript out of range means an object is improperly named. Sheet "80" might be "8O" instead, or have a hidden space. Check your sheetnames.

+ 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