+ Reply to Thread
Results 1 to 8 of 8

An Array to hold Arrays?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Question An Array to hold Arrays?

    I've been playing around with the Add-Ins tab lately and am looking at improving loops when adding Popup controls.

    Each popup control has a number of macros linked to it (as Control buttons) and the names of these macros are recorded in a variant array.

    Please Login or Register  to view this content.
    Now when adding these popups to the Add-Ins tab, I need to repeat the code for every popup instance which is messy and inefficient. I was wondering:
    1. whether a "parent" array could be used to hold all the popup arrays declared in the procedure?
    2. If yes to above, can it be worked so that I don't need to define the names/number of the popup arrays when adding to the parent array?
    3. How can I loop through the parent array to repeat the add ControlButtons code for each Popup array inside the parent array?
    4. Am I on the wrong track and should be looking at Collections instead (which I know next to nothing about)?
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: An Array to hold Arrays?

    I suspect so, why not post a couple of iterations of our code so we can have a look?

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: An Array to hold Arrays?

    Why not:
    1. Use a table driven approach? (plenty of examples out there)
    2. Use the Ribbon properly? (can still incorporate point 1)

    Edit: didn't notice who the asker was. New answer: yes, you can have an array of arrays.
    Last edited by romperstomper; 08-28-2013 at 01:42 AM.
    Remember what the dormouse said
    Feed your head

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: An Array to hold Arrays?

    Good to hear from you again Romperstomper!

    Yes I know that nested arrays can be done however I am struggling to work this into the add-in without repeating all the "add controls" code for each array - I would prefer to loop to add the controls to each popup and also have it flexible enough to quickly and easily add another popup array without having to code a change in size to the "parent" array

    I agree that a custom tab on a Ribbon is a much better approach. However I'm curious as to how much you can push the limits of Add-Ins without resorting to a custom tab.

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: An Array to hold Arrays?

    Thanks Kyle. See attached dummy workbook. It's kept in the format of XLSM as it's easier for testing
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: An Array to hold Arrays?

    I tried adding the arrays as
    Please Login or Register  to view this content.
    but it didn't work.

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: An Array to hold Arrays?

    It doesn't have to be an Add-In. Say you have a Form and you wish to assign X number of Lists to it. The same principle applies.

    I can't think of how to use a nested array of 1D arrays without hardcoding the name of each 1D array into the nested array. More importantly, how do I get the loop to work on adding the controls/lists for each array in the nest?

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: An Array to hold Arrays?

    I have come up with a "near enough" solution.

    I created a private variant function containing the arrays I want to add. I then set the function as an array of all these arrays (not what I was hoping for, because it means that if I want to add a new array, I need to not only hard code the new array name as a new Dim, I need to add another name to the Nested array)

    In the create controls code, I loop through each array in the Nested array. I set a temporary variant as the current array in the nest and then run a secondary loop through the temp array to add the controls. See code at bottom of this post.

    In answer to my original questions:
    1. Yes (nested array as variant function)
    2. Apparently not (or if there is, nobody is saying! )
    3. Yes - see code in this post
    4. Collections not needed after all



    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. [SOLVED] New to arrays-how do I build new array while filtering first array?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-03-2013, 05:59 AM
  2. To hold or not hold CTRL down
    By Sebastian1942 in forum Excel General
    Replies: 2
    Last Post: 05-02-2010, 02:17 PM
  3. Extracting 3 Arrays from 1 Array
    By Chuckles123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2007, 03:55 PM
  4. treeview node tag hold array?
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2005, 08:05 PM
  5. An array of Arrays
    By cybercab in forum Excel General
    Replies: 0
    Last Post: 05-04-2005, 09:18 AM

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