+ Reply to Thread
Results 1 to 21 of 21

How to use array declared in VBA in spreadsheet

  1. #1
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    How to use array declared in VBA in spreadsheet

    I have posted a similar thread at https://www.mrexcel.com/forum/excel-...provement.html

    I am declaring a table as an array.

    Please Login or Register  to view this content.
    How can I use the myarray array in my excel spreadsheet? I want to VLOOKUP the array.
    Last edited by waimea; 03-03-2019 at 02:36 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,001

    Re: How to use array declared in VBA in spreadsheet

    Could you explain in more detail what you’re trying to do?
    Providing an example would help.

  3. #3
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    Hi Akuini,

    thank you for your reply!

    I am trying to load several tables into arrays and then I want to vlookup the arrays in my spreadsheet.

    Ex. I have a combobox named combobox1 and it has two items.

    Please Login or Register  to view this content.
    I want to load a table into an array

    Please Login or Register  to view this content.
    Then in my spredsheet (not userform) I want to VLOOKUP the combobox value in the array/arrays.

    Please Login or Register  to view this content.
    I am not sure if this is faster/better then just using the underlaying table to VLOOKUP on?

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,001

    Re: How to use array declared in VBA in spreadsheet

    Are you trying to compare which one is faster, doing VLOOKUP in the table or in the array?
    In my opinion, I never tested it, it would be just the same, because VLOOKUP only find the value once.
    Usually the difference is noticeable when we doing an iteration\looping. Looping through an array is faster than looping through a range, especially if you’re working on a large data.

  5. #5
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    Hi Akuini,

    Yes, I want to know which one is faster but before I try it on large data I want to see if there is a notable difference.

    I am thinking that maybe I can assign a named range to the array? Or is there a better way?

  6. #6
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,001

    Re: How to use array declared in VBA in spreadsheet

    Or is there a better way?
    Better way to what?
    Maybe if you can describe your situation & what the goal is, we can discuss better ways to do it.

  7. #7
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    Hi Akuini,

    thank you for your reply! I am asking for any way to access an array declared in an module in my spreadsheet??


    I have a spreadsheet that uses a lot of vloopkup and match/countifs/sumifs and I am trying to loop through two combobox and each iteration of the loop takes a couple of seconds.

    I am looking at ways of speeding up the process.

    So I select an item in combobox1 and then the sheet calculates all possible combinations of two comboboxes, both comboboxes have 320 items.

    I am using two for loops to loop through the comboboxes and I am storing the results of every iteration in an array.

    What I am thinking is if I can run the vlookup and match/countifs and sumifs on an array and then run the loop?

  8. #8
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,001

    Re: How to use array declared in VBA in spreadsheet

    Can you attach your sample workbook?

  9. #9
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    It is a very large file and it would take me hours to create a sample :/

    From what I have googled it seems like I can assign an array to a named range and even hide the range from the user.

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

    Re: How to use array declared in VBA in spreadsheet

    It is slower to use worksheet functions on arrays than on the worksheet. Excel is optimised for performing calculations on worksheets

  11. #11
    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,299

    Re: How to use array declared in VBA in spreadsheet

    Surely, if you create a Named Range, it is addressing a range/cell(s) on a worksheet.

    Generally speaking, people define an array in VBA and assign a range to it in order to process it internally rather than loop through the range on the worksheet itself.

    Still not sure I understand what you are trying to do.
    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


  12. #12
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    Kyle123, TMS,

    thank you for your replies!

    I want to speed up my code.

    I am probably explaining it poorly.

    I want to read all my data (100+ data tables) into arrays, then vlookup all data and create a MASTER array, then run my code on it and then dump it to a sheet.

    Maybe I am going down the wrong path?

  13. #13
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    On a subset of my data I am calculating all possible combinations of 40 * 40 items which gives me 1600 items.

    This subset of data takes 20 minutes and 32 seconds minutes to complete. So I want to improve the speed of my code.

    Now it takes 1,33 seconds per iteration.

    Perhaps using many arrays isn't the solution?
    Last edited by waimea; 03-03-2019 at 10:42 AM.

  14. #14
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    Now I have tried using named ranges for arrays, however the 8192 characters limit for formulas makes the spreadsheet be unreliable?

    Is there another way to access an array declared in VBA in my spreadsheet?

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

    Re: How to use array declared in VBA in spreadsheet

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  16. #16
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    I just tried it with one loop for table vlookup and one loop for vlookup with array in named range.

    The first one takes 0,25 seconds and the second one takes 0,25 seconds. So no point in storing arrays in named ranges I guess.

    Also, it seems like arrays in named ranges breaks the 8000 limit and corrupts the file.
    Last edited by waimea; 03-05-2019 at 03:39 PM.

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

    Re: How to use array declared in VBA in spreadsheet

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  18. #18
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Sweden
    MS-Off Ver
    2016.
    Posts
    397

    Re: How to use array declared in VBA in spreadsheet

    Hi Kyle,

    the named range corrupts my file and even if I try to save it as binary workbook it says that the file is corrupted and not possible to save on my computer.

    Please Login or Register  to view this content.
    I was trying to figure out if storing an array in a named range was faster and it seems like it isn't.

    Please Login or Register  to view this content.

  19. #19
    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,299

    Re: How to use array declared in VBA in spreadsheet

    you seem to be wasting a lot of time with these arrays. It's like going from A to B via C when, in fact, you can go directly from A to B.

    You don't need VBA to load the Structured Table into an Array and then create a Named Range that refers to the "Array" ... the Array is just the Table ... it hasn't moved from the worksheet into a VBA defined variable.

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

    Re: How to use array declared in VBA in spreadsheet

    Look, no one can help you as long as you continue to refuse to upload a sample workbook. You’re wasting our time and yours. I’m afraid I’m ducking out of your threads until you upload one, without a workbook, we’re shooting in the dark.

  21. #21
    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,299

    Re: How to use array declared in VBA in spreadsheet

    I'm with Kyle ...

+ 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] Determine if a value is in declared array
    By pmchris in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-28-2018, 03:39 PM
  2. Scope of Array declared in Excel Macro-Enabled Add-In
    By eadamy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-11-2017, 07:47 PM
  3. with i as integer different format for an declared array
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-09-2017, 02:11 PM
  4. Refresh an already declared variable
    By EchoPassenger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2016, 04:56 AM
  5. array names declared on the fly
    By GunNam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2010, 10:22 PM
  6. Non-declared variable
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2007, 10:01 AM
  7. How to reference a public array (declared in module) from a proced
    By Amzee in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-11-2005, 05:06 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