Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to setup a global array????????

How to setup a global array????????

How to setup a global array????????

Another quick question please guys. I need to make an array global so that other sub and functions can access it - how do I do this?

I would be using the Sub uto_Open to get it to intially read some data from a file into an array and then instead of having to query the file it just queries the array.

Thanks again folks,


RE: How to setup a global array????????

Sorted now. Thanks.

RE: How to setup a global array????????

Why do I keep on thinking your name is Minty Ginger? :-S

If you want a global scope to your array it's just the same as for "normal" variables.

eg declare array in Module1 which also contains sub to set up array:

Public str_arr() As String
Dim i As Integer
Sub set_up_arr()
ReDim str_arr(4)
For i = 0 To 4
    str_arr(i) = "Mr Man " & i + 1
End Sub

Note the use of "Public" rather than "Dim" - this ensures code in otehr modules can "see" array.

I used array in Sheet1 module by tying it to worksheet change event:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
For i = 0 To 4
    MsgBox str_arr(i)
End Sub

try it for yourself - you should be able to get it working.

Moral is - just use Public keyword.

RE: How to setup a global array????????

Oooops, glad you sorted it yourself.

RE: How to setup a global array????????

No, it's appreciated. I just put Global for the variable at the very top ofeverything - so not in any functions or subs and then fill it in a sub and use it in another sub. Seems to work.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close