+ Reply to Thread
Results 1 to 11 of 11

Way to retrieve values from a dynamic named range?

  1. #1
    Registered User
    Join Date
    06-07-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Unhappy Way to retrieve values from a dynamic named range?

    Hoping someone on here knows the answer, it's probably something simple I'm overlooking.

    Currently we have a sheet with pre-defined values in columns such as:
    A
    1 MyValueA
    2 MyValueB
    3 MyValueC


    Which I refer to as a named set:
    MyNamedSet: =Lists!$A$2:$A$3

    And pull into an array in my VB code:
    MyArray = Evaluate(Names("MyNamedSet").RefersTo)

    Thus yielding the following array:
    MyArray (1,1) = MyValueA
    MyArray (1,2) = MyValueB
    MyArray (1,3) = MyValueC

    What I would like to do with this named set is make it to where it allows the user to add additional rows to the Lists worksheet which are then pulled into the array at macro runtime.

    To this end, I changed the Named item to be
    MyNamedSet: =OFFSET(Lists!$A$1,0,0,COUNTA(Lists!$A:$A),1)

    My hope was that this would automatically pull in the entire set of values from the "A" column, but instead it simple returns MyArray = "=OFFSET(Lists!$A$1,0,0,COUNTA(Lists!$A:$A),1)".

    Any ideas as to what I am doing wrong? I am trying to elimitate the need for the named range to be updated every time a new column value is added, am I going about things the correct way?
    Last edited by OLDWEASEL; 06-09-2011 at 11:51 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,433

    Re: Way to retrieve values from a dynamic named range?

    Might be easier for people to investigate if you post a sample workbook with data and code in context.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Way to retrieve values from a dynamic named range?

    I tried the exact same thing and it works on my computer. See attached file.
    Pierre
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-07-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Way to retrieve values from a dynamic named range?

    Thanks Pierre, what's odd is that if I add an additional value, only the new value is getting retrieved, not sure what's going on here.
    Last edited by OLDWEASEL; 06-08-2011 at 09:23 AM.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Way to retrieve values from a dynamic named range?

    What if you use:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    06-07-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Way to retrieve values from a dynamic named range?

    Quote Originally Posted by romperstomper View Post
    What if you use:
    Please Login or Register  to view this content.
    Romper, the only issue with that statement is that without the EVALUATE is just returns the OFFSET line of code.

    Okay, figured out what was going on with my call, now the only issue I am having is that for some reason it is storing the values as a two-dimensional array (with the second dimension always being empty), is there any way to perform the retrieval directly into a one-dimensional array?

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Way to retrieve values from a dynamic named range?

    It shouldn't do - note the RefersToRange, not RefersTo.

    If you assign the value of a multiple cell range to a Variant, you always get a 2D array. If you don't want that, then Transpose it.

  8. #8
    Registered User
    Join Date
    06-07-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Way to retrieve values from a dynamic named range?

    Quote Originally Posted by romperstomper View Post
    It shouldn't do - note the RefersToRange, not RefersTo.

    If you assign the value of a multiple cell range to a Variant, you always get a 2D array. If you don't want that, then Transpose it.

    <Bonks Self> - You're right, I missed the RefersToRange part, my apologies.

    How would I add a Transpose to that statement? My efforts so far are erroring off.

    Thank you for your patience so far!

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Way to retrieve values from a dynamic named range?

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-07-2011
    Location
    Cincinnati, OH
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Way to retrieve values from a dynamic named range?

    Quote Originally Posted by romperstomper View Post
    Please Login or Register  to view this content.

    Thank you so much! Have spent entirely too long trying to figure this out

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Way to retrieve values from a dynamic named range?

    Glad to help.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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