+ Reply to Thread
Results 1 to 3 of 3

public or global array

  1. #1
    shishi
    Guest

    public or global array

    Hi,

    I am trying to generate a public or global array. The situation is
    like this...I have couple of subroutines..Each of these subroutines
    needs data stored in an array. I wish to generate this array and make
    it public or global in one subroutine and make it available to all
    other subroutines..How can I accomplish that..The code snippet as
    below..

    Sub GeneratePublicArray()
    Dim MyArray As Variant
    Dim mCell As Range

    Set mCell =
    ThisWorkbook.Sheets("SPECS").Range("NO_OF_MODULES").Offset(3, 1)

    MyArray = Application.Transpose(Range(mCell, mCell.End(xlDown)))

    End Sub


  2. #2
    Tom Ogilvy
    Guest

    Re: public or global array

    In a general module at the top if the module, declare it as public. don't
    declare it anywhere else.

    Public MyArray as Variant

    Sub GeneratePublicArray()
    Dim mCell As Range

    Set mCell =ThisWorkbook.Sheets( _
    "SPECS").Range("NO_OF_MODULES").Offset(3, 1)

    MyArray = Application.Transpose(Range(mCell, mCell.End(xlDown)))

    End Sub

    --
    Regards,
    Tom Ogilvy



    "shishi" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I am trying to generate a public or global array. The situation is
    > like this...I have couple of subroutines..Each of these subroutines
    > needs data stored in an array. I wish to generate this array and make
    > it public or global in one subroutine and make it available to all
    > other subroutines..How can I accomplish that..The code snippet as
    > below..
    >
    > Sub GeneratePublicArray()
    > Dim MyArray As Variant
    > Dim mCell As Range
    >
    > Set mCell =
    > ThisWorkbook.Sheets("SPECS").Range("NO_OF_MODULES").Offset(3, 1)
    >
    > MyArray = Application.Transpose(Range(mCell, mCell.End(xlDown)))
    >
    > End Sub
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: public or global array

    Do not declare the array within a sub. Instead declare it at the top of a
    standard code module.

    public myArray as Variant

    sub Test
    myArray(0) = "Test"
    exit sub

    Be careful with overusing globals as they can be tough to debug. If you have
    a bunch of different procedures all modifying the varaible then if the
    variable contains the wrong value at any point in the execution, it can be
    hard to track down which procedure added the incorrect value.
    --
    HTH...

    Jim Thomlinson


    "shishi" wrote:

    > Hi,
    >
    > I am trying to generate a public or global array. The situation is
    > like this...I have couple of subroutines..Each of these subroutines
    > needs data stored in an array. I wish to generate this array and make
    > it public or global in one subroutine and make it available to all
    > other subroutines..How can I accomplish that..The code snippet as
    > below..
    >
    > Sub GeneratePublicArray()
    > Dim MyArray As Variant
    > Dim mCell As Range
    >
    > Set mCell =
    > ThisWorkbook.Sheets("SPECS").Range("NO_OF_MODULES").Offset(3, 1)
    >
    > MyArray = Application.Transpose(Range(mCell, mCell.End(xlDown)))
    >
    > End Sub
    >
    >


+ 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