Help with Array Declarations

M

Mark \(InWales\)

Hello All

Just a quickie. I have two Userforms that use exactly the same information
in a combobox (different names) if I wanted to only declare the Array once
where would I put it? Both Userforms have the Array declared on the
Userform_Initialize() event so if one of the Userforms wasn't loaded (highly
likely) where and how should I declare?

Many thanks for any help

Mark (InWales)
 
C

Chip Pearson

Mark,

You can declare it as a Public variable in a regular code module.
Then, ReDim it, if necessary, in the form's code module.

'[in Module 1]
Public Arr() As String

'[in Form module]
Public Sub Userform_Initialize()
ReDim Arr(1 to whatever)
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
T

Tom Ogilvy

You should declare it as a global variable in a general module. Then
initialize it there as well.

Then either/both userforms can see it.
 
L

Lonnie M.

Hi, insert a module and rename it to 'Main'. At the top declare the
array as a global--"Public myArray As Varriant".
Insert a Procedure within 'Main' and write the code to populate your
array and then call that procedure from your form initialization code.
HTH--Lonnie M.
 
M

Mark \(InWales\)

Many thanks both.

Mark
Tom Ogilvy said:
You should declare it as a global variable in a general module. Then
initialize it there as well.

Then either/both userforms can see it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top