+ Reply to Thread
Results 1 to 6 of 6

Best way to code a repeatedly used array?

  1. #1
    Registered User
    Join Date
    10-28-2008
    Location
    Guildford, UK
    Posts
    5

    Best way to code a repeatedly used array?

    Hi all

    I am trying to code a function that needs to compute a data array specified by the user to calculate the output. Lets called the function func().

    This function will be used about 1000 times in a spreadsheet and the data array will need to be quite large so i would like to minimise the number of times the data array needs to be calculated to make the spreadsheet as quick as possible.

    so if the user inputs func("array 1", ....). I play to write a sub function to turn "array 1" into the required data array. Ideally i would like to store this data array as a global array called "array 1" so that if another cell needs "array 1" it will be able to just use it rather than have to recalculate it.

    Is this all possible to have an unknown number of global arrays stored with unknown names (Specified by the user)?

    Thanks

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

    so if the user inputs func("array 1", ....).
    Yes, it's possible, but not with that syntax. Explaining how requires more information than you have provided.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi, and welcome to the forum.

    Can we double check whether you really need to use a VBA function? As soon as you invoke VBA there is a time overhead each time you use an Excel function to call a VBA function. In other words even if you have a global array held in the VBE, it sound like your XL functions will be calling it a lot. The overhead is not necessarily in the size of the array but the number of times you refer to it.

    Is a standard data table held in the XL application not a viable option? It would certainly process things far quicker.

    Can you describe in a little more detail what you are trying to compute>

    Rgds

  4. #4
    Registered User
    Join Date
    10-28-2008
    Location
    Guildford, UK
    Posts
    5
    Thanks for the welcome - what information do i need to specify?

    My VBA isn't great but essentially if i input the text "array 1" into a cell, can i create a function that would create a 10x10 array say called "array 1" that would be stored globally for all functions to see?

  5. #5
    Registered User
    Join Date
    10-28-2008
    Location
    Guildford, UK
    Posts
    5
    Thanks also for the welcome Richard.

    I need to create an excel add in that can be be saved onto any computer.

    The time intensive part of my current function is to take an (nx1) array and multiply it by a (nxm) array to produce an (nxm) array (with some modifications depending on the user's other inputs)

    The data arrays are all saved on excel sheets in the add-in. At the moment the function i have computes the (nxm) array each time the function calls which is hugely inefficient.

    My idea was to create global arrays that all the functions could see and cut down the speed of the 1000 functions in my spreadsheet.

    Hope this helps?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You can select a 10x10 area and type array1 in the Names box (left of the formula bar), and that's available to VBA.

    You can create dynamic named ranges, for which there are hundreds (or thousands) of examples here in the forum.

+ 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