+ Reply to Thread
Results 1 to 3 of 3

Passing an array into multiple Modules

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Passing an array into multiple Modules

    I have 5 arrays (one for Mon - Fri) that I have been re-writing for 3 different modules that are called at 3 different times a day. For example, on Monday Module_1 has the Array written out, Module_2 has the same Array written out, and Module_3 has the same array written out...

    My question is...since it is the same Array being called 3 different times a day, is there a way to declare the Array once, and then call it from Module_1, Module_2, and Module_3? Would cut down on code writing TREMENDOUSLY!!!!


    Actually I thought of one difference in the Arrays.....In Module_1 the workbooks are called like this "Test1.xls" whereas in Module_2 and Module_3 they are only called with "Test"...that may throw a monkey wrench into anything...Idk, but help is appreciated
    Last edited by jo15765; 11-13-2011 at 01:47 AM. Reason: Thought of one difference in the arrays

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,241

    Re: Passing an array into multiple Modules

    Hi jo15766,

    You need to Dim your variables as global. Read about Project and Global Scope on:
    http://www.cpearson.com/Excel/Scope.aspx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Passing an array into multiple Modules

    So if I understand this correctly I could declare my Array as
    Global Array = Array_Monday_1("Test.xls", "Test1.xls")
    And I could set it:
    Global Function Declare_Arrays()
    Global Array = Array_Monday_1("Test.xls", "Test1.xls")
    Global Array = Array_Monday_2("Test", "Test1")
    Then to actually call the Array from within the module, I would use:
        Dim varBooks
        Dim varbook
        Dim wb As Excel.Workbook
    
        varBooks = Array_Monday_1
    Do I have a grasp on that?

+ 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