+ Reply to Thread
Results 1 to 10 of 10

3 dimensional array

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    3 dimensional array

    Hi all,

    I am trying to create a 3D array with VBA and then store the data in a "named range" to use it in one of my formulas. However, I don't seem to get it working. I have three named ranges on my worksheet, so each of them should represent an "area" and each of these areas contain 8 rows times 4 columns.

    Below the code I have so far:

    Please Login or Register  to view this content.
    Once the array has been added to the workbook as a "named range" called "Cluster", I want to access the data by using an INDEX formula as below, where 1 = row 1, 2 = column 2, and 3 = area 3. Hence the result should be 52 as it refers to the second column, first row in range "KNITS".

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,691

    Re: 3 dimensional array

    A name must refer to a formula that returns a worksheet range. You are trying to create a name to refer to a VBA array.

    If you first write your array Clus to a set of cells (in the way your data in arranged in your example), then name that set of cells Cluster, your INDEX formula will work. But I don't think you need to do that because you are reading the Clus data from the worksheet to begin with.

    Here is your example. I have added the named range Cluster, and now your INDEX formula works. I didn't touch your code and I am not sure you even need the code. The most your code would need to do is analyze the worksheet data to create the named range.
    Attached Files Attached Files
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: 3 dimensional array

    Quote Originally Posted by 6StringJazzer View Post
    A name must refer to a formula that returns a worksheet range. You are trying to create a name to refer to a VBA array.
    That's not correct. You can certainly assign a 1- or 2-D VBA array to a name (or indeed just a number, text, or other formula). What you can't do is assign an array with more than 2 dimensions, since Excel has no way of representing that in a formula.

    If code is required to create one named range, then you might do something like this:

    Please Login or Register  to view this content.
    Rory

  4. #4
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: 3 dimensional array

    Thanks Rory!!

    This isn't what I wanted to hear but helping a lot in finding the right way to use arrays/ named formulas. I have actually managed to store the data in a 2D array rather than 3D. Though, it's quite a lot of data for a named formula.

    I get to about 3000 data points in total in my actual data set. This is way beyond the expected 255 character limit, however, for some reason it still works?? What is the limit for named formulas? I tried 5000 data points and my Excel crashed when saving the file...

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: 3 dimensional array

    I would recommend you don't store anything longer than 255 characters in a name. Why do you need to store the data as an array, not a range?

  6. #6
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: 3 dimensional array

    The data is coming from a different workbook, I use it in a formula to test for certain conditions, so I just wanted to store a "few" numbers without having to paste them anywhere in a sheet first...

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: 3 dimensional array

    Personally, I would suggest you do store it in a range. It will make auditing your results a lot easier.

  8. #8
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: 3 dimensional array

    you mean storing in a sheet first then analyzing the data from there?

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: 3 dimensional array

    Yes. It'll be much easier to see where the results come from that way.

  10. #10
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: 3 dimensional array

    True... won’t have much of a choice anyway I guess! Thanks again both for helping out!!

+ 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. [SOLVED] Convert 2 dimensional array to 1 dimensional
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2018, 05:20 AM
  2. Help converting one-dimensional array to multi-dimensional array
    By puzzlelover22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 06:48 AM
  3. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  4. [SOLVED] Convert one dimensional array into two dimensional array
    By mohammed sabr in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-26-2015, 10:34 AM
  5. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  6. Creating a 2-dimensional array from a 1-dimensional list
    By guywithcamera in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-27-2008, 06:34 PM
  7. Create One-Dimensional Array from Two-Dimensional Array
    By Stratuser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 05:06 PM

Tags for this Thread

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