Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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" wrote in message
ups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public Array in a form? lux770[_3_] Excel Programming 4 July 28th 05 08:49 AM
public array Circe[_2_] Excel Programming 6 May 17th 05 11:45 PM
Public vs Global quartz[_2_] Excel Programming 2 February 9th 05 06:20 PM
declaring a public array JT[_2_] Excel Programming 3 July 27th 04 11:18 PM
Public Array Brent McIntyre Excel Programming 5 September 23rd 03 12:53 AM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"