+ Reply to Thread
Results 1 to 15 of 15

Issue Accessing Public Multidimensional Array in Another Module

  1. #1
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Angry Issue Accessing Public Multidimensional Array in Another Module

    Hi all,

    As the title says, I am having an issue accessing a Publicly declared multidimensional array in another module. Sorry if this seems obvious or badly written, I'm new to VBA. My project is set out as below:

    Module 1 - Contains all my publicly declared variables, including the multidimensional array. The code for that is:
    Please Login or Register  to view this content.
    Module 2 - Here I ReDim the array as a 2 dimensional array and add the values to it.
    Please Login or Register  to view this content.
    At this point, when I Watch the tableArray variable, it displays correctly, with data populated in each of the collections (although some are left blank intentionally)

    After this I have a final module - where the problem is. The Sub in this module is run after the user double clicks on certain cells within a worksheet (but this will always happen after the Sub in the second module has run):
    Please Login or Register  to view this content.
    I get the error on double clicking: "Subscript out of range", and the watch now reports the tableArray as type Collection(0 to -1), with no data. Why, if this is a public variable, is the data not being retained properly?

    Thanks in advance!

    Sprucie

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Hello Sprucie,

    Welcome to the Forum!

    Change your declaration in Module1 to a Variant type instead of a Collection object.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Hi Leith, thanks for the quick response.

    Unfortunately I am still getting the same error message when running the Sub in module 3. Now on the Watch it says the type is Variant/Variant(), but that is the only change.

    I am adding the code to call the final sub to the worksheet programatically if that makes any difference?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Can we see the rest of the code and/or a sample workbook?
    If posting code please use code tags, see here.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Hello Sprucie,

    I am adding the code to call the final sub to the worksheet programatically if that makes any difference?
    Are you adding code to an existing procedure?

    It appears you are using a multidimensional array, collection objects, and a Dictionary object. For what purpose?

  6. #6
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Here is all code as requested:

    Module 1
    Please Login or Register  to view this content.
    Module 2 - lots of code:
    Please Login or Register  to view this content.
    Module 3 is all that I posted:

    Please Login or Register  to view this content.
    I don't know if that is useful to you at all, but that is everything.

    Leith - I am using the dictionary as a sort of database, to store the Deal class variables so I can easily retrieve them by their deal number at any point. The Array is then used so that I can display the number of deals in a table based on certain criteria and the Collection is so that I can store a number of deal numbers for each cell.

    I also add that code to a blank workbook - the one created in Module 2 called "Deal Data":
    Please Login or Register  to view this content.
    Last edited by Sprucie; 02-23-2016 at 01:56 PM.

  7. #7
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Sorry, I created duplicates...
    Last edited by Sprucie; 02-23-2016 at 01:33 PM.

  8. #8
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Sorry, another duplicate
    Last edited by Sprucie; 02-23-2016 at 01:35 PM.

  9. #9
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Duplicate #3
    Last edited by Sprucie; 02-23-2016 at 01:56 PM.

  10. #10
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Duplicate #4
    Last edited by Sprucie; 02-23-2016 at 01:38 PM.

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

    Re: Issue Accessing Public Multidimensional Array in Another Module

    I'm pretty sure that:
    Please Login or Register  to view this content.
    Will reset the project and all your variables.

    Adding code at runtime is not good practice. Why can't you use a template?

  12. #12
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Hi Kyle,

    As I mentioned I'm pretty new to VBA, that section you're talking about seems like it could be the proble. I'll look into templates.

    Thanks!

  13. #13
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    I've looked into templates and it doesn't seem like it will work in this case - I need the macros to run on multiple machines without issues.

    Can anyone advise a way to adapt this code so it doesn't reset the project/variables:
    Please Login or Register  to view this content.

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

    Re: Issue Accessing Public Multidimensional Array in Another Module

    How is that a restriction of a template workbook?

  15. #15
    Registered User
    Join Date
    03-05-2014
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Issue Accessing Public Multidimensional Array in Another Module

    Hi Kyle, I think I've understood what you're suggesting now, and I don't see why it wouldn't work, so I'll mark it as solved. Many thanks to everybody for their quick responses.

    Sprucie.

+ 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] Accessing public variable from form
    By JasonLeisemann in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2015, 12:41 PM
  2. [SOLVED] Accessing array in a class module
    By chipnputt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2014, 11:09 PM
  3. [SOLVED] Class module / multidimensional array?
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-09-2013, 09:31 AM
  4. Using the ReDim array function in a multidimensional array in excel
    By Doruli in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-05-2012, 01:43 PM
  5. accessing array of an userform from a Sheet/module macro code
    By stanigator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2007, 09:34 PM
  6. 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
  7. Replies: 1
    Last Post: 01-05-2005, 06:06 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