+ Reply to Thread
Results 1 to 8 of 8

Create Named Ranges from Array

  1. #1
    Registered User
    Join Date
    10-06-2013
    Location
    Alabama
    MS-Off Ver
    Excel 2007
    Posts
    15

    Create Named Ranges from Array

    Perhaps stupid question.

    Is it possible to create a named range by referring to an Array as opposed to referring to a Range that contains the data? If so would appreciate code showing how to do it.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Create Named Ranges from Array

    Is this the sort of thing you mean?

    Please Login or Register  to view this content.
    Then with cell formula you could use the following to return Green

    =INDEX(RGB_ARRAY,2)
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-06-2013
    Location
    Alabama
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Create Named Ranges from Array

    Andy, your example sort-of. It's a bit more complicated and I can't get my brain to arrive at a solution for indexing the array to get the proper data.

    The code below works great. But it requires taking data from an array, putting it into a range, and then extracting columns of data from that range to create individual Ranges of Named Range data for use in Excel formulas. For efficiency, I'd like to change the "RefersTo" instruction to extract data directly from the Array "aDataArray".

    Below is a small sample of the data range "rLogDataOnScratchSheet". The code loops through each column of the range and creates a Named range that points to the respective column of data. For example, Column A would become the first named range, Col B the second, etc.

    Please Login or Register  to view this content.
    Thanks in advance.
    Attached Files Attached Files
    Last edited by toliphint; 08-09-2020 at 05:17 PM. Reason: Provide attachment

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Create Named Ranges from Array

    Your attachment is invalid... please use the instructions in the yellow banner near the top of this forum's window to upload a copy of your workbook.

  5. #5
    Registered User
    Join Date
    10-06-2013
    Location
    Alabama
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Create Named Ranges from Array

    Quote Originally Posted by Rick Rothstein View Post
    Your attachment is invalid... please use the instructions in the yellow banner near the top of this forum's window to upload a copy of your workbook.
    Updated above. Tks.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Create Named Ranges from Array

    Given an array, this will put its elements in a name
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Registered User
    Join Date
    10-06-2013
    Location
    Alabama
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Create Named Ranges from Array

    Quote Originally Posted by mikerickson View Post
    Given an array, this will put its elements in a name
    An elegant solution. Thanks. When time permits, will evaluate against current code on my 200K+ element array and advise. Thanks again.

  8. #8
    Registered User
    Join Date
    10-06-2013
    Location
    Alabama
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Create Named Ranges from Array

    Many thanks mikerickson for the reply and again elegant solution, but it does not work for me. I have over 200K+ array elements and the length of a string is greatly exceeded even when parsing my array to smaller sub-sets.

    Here's what I've concluded unless someone can prove otherwise:
    1.
    When a Range Name is added, it must point to (ReferTo) a Range and nothing else (except perhaps a string but too short for my app). When it points to an array of data, the created range names fail in Excel due to invalid data as indicated by information in the Name Manager (Ctrl-F3). It shows:
    Value = {...}
    RefersTo = {The data in the array}

    2.
    But when a range is used as the data source in the RefersTo instruction, we see the following in the Name Manager and all is good:
    Value = {The data in the range}
    RefersTo = The range which contains the data referred to/pointed to

    So bottom line, despite being allowed by vba code, it seems for large data sets a range must contain the data to which a RefersTo instruction refers.

    If this can be proven wrong, I'd love it because referring to an array of data as opposed to writing a range from an array and then ReferTo that range cannot be as efficient as referring directly to the array -- especially when dealing with very large data sets.

    Comments/Thoughts?

+ 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. VBA To Create Named Ranges
    By tschuman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2013, 03:07 PM
  2. Replies: 2
    Last Post: 06-01-2011, 07:43 AM
  3. 2D Array of named ranges
    By hilander in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-02-2008, 08:02 PM
  4. Array Formulas and Named Ranges
    By cpadude in forum Excel General
    Replies: 3
    Last Post: 10-04-2007, 11:33 AM
  5. sumproduct using array of named ranges
    By Exceler in forum Excel General
    Replies: 1
    Last Post: 08-27-2006, 12:35 PM
  6. [SOLVED] Can you create dynamic named ranges containing array formulas?
    By Marie J-son in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2006, 09:10 AM
  7. Create named ranges
    By loopoo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2005, 09:16 AM
  8. Looking up named ranges as an array
    By L.White in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2005, 05:05 PM

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