+ Reply to Thread
Results 1 to 7 of 7

Named Ranges on Multlple Worksheets

  1. #1
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Named Ranges on Multlple Worksheets

    I've recently converted a number of ranges to Named Ranges to try and 'protect' if the user adds any rows or columns to the sheet.

    I have the below code basically 5 different times, for 5 separate spreadsheets.

    I had thought that by also assigning named ranges to everything that I could then possible combine all the named ranges together into one singe macro. However, those attempts fail with a Method 'Range' of object '_Global' failed.

    Essentially, I'm trying to learn if you can combine multiple Named Ranges from separate worksheets into 1 macro, or if you need to Select each sheet separately. Just trying to learn and improve. I thought about also trying to learn and create a 2 dimensional array of the sheet name and named ranges for each, and then loop it that way.

    Or assign separate 'rows_rng' and 'col_rng' for each sheet?

    The below works fine. Only trying to learn why adding names ranges from other sheets will fail (I did removed the Sheets.Select when trying to add additional named ranges from other sheets)
    Please Login or Register  to view this content.

  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: Named Ranges on Multlple Worksheets

    You can perhaps play with the UNION(range1, range2) function, but I think creating a "range" is limited in scope to one parent object. You will most likely have to resort LOOPING through the various ranges on the various sheets and adding them to your chart specifically as a new series for each range. Not my expertise, yet.
    _________________
    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
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Named Ranges on Multlple Worksheets

    Quote Originally Posted by JBeaucaire View Post
    ... a "range" is limited in scope to one parent object ...
    Limited to cells on a single worksheet, absolutely, yes.

    Even 3D ranges (a common range across two or more contiguous worksheets), which are accepted by some functions (e.g., =SUM(Sheet1:Sheet2!A1:A3)) are accessible only via the UI, not in VBA; you can't pass a 3D range to a UDF.
    Last edited by shg; 09-28-2014 at 04:14 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Named Ranges on Multlple Worksheets

    Thanks guys and to simply

    This below which includes 2 named ranges from 2 different worksheet fails because VBA can't handle 3D Ranges? Am I understanding correctly?

    Please Login or Register  to view this content.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Named Ranges on Multlple Worksheets

    Yup .

  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: Named Ranges on Multlple Worksheets

    And if those ranges WERE on the same page I think your results would not be what you wanted.

    If you want make a range of only the cells A1:B2 and E4:F5, a total of 8 cells, your syntax above:

    Please Login or Register  to view this content.
    ... would result in a range of A1:F5, a total of 15 cells. Not what you want.

    To get JUST the individual ranges together without the extra cells in between, use the UNION method:

    Please Login or Register  to view this content.
    Now THAT is only 8 cells still. All of that above holds true for named ranges, too.


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Named Ranges on Multlple Worksheets

    To get JUST the individual ranges together without the extra cells in between, use the UNION method:
    Please Login or Register  to view this content.
    Or

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Define only 2 named ranges from a list of named ranges...
    By abhi900 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-29-2014, 04:20 AM
  2. Replies: 4
    Last Post: 02-06-2014, 11:13 PM
  3. Replies: 7
    Last Post: 05-27-2013, 01:40 PM
  4. Excel 2007 : sum named ranges in different worksheets
    By joethengineer in forum Excel General
    Replies: 1
    Last Post: 08-26-2011, 02:44 PM
  5. Accessing Named Ranges on different worksheets
    By gladst_j in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2011, 09:55 AM

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