Dynamically addressing global arrays

JSSWAT

New Member
Joined
Jul 12, 2010
Messages
22
Hello everyone and good morning! Or whatever it is where you are :)

So I have created a few macros which gather data from tabs into globally defined arrays. I would like to simplify by creating a single macro for this action. To do this I was planning on passing the name of the array to a sub/function which would handle the rest.

My problem is this...

I cannot get the macro to use the string as the name of the array...

I assumed there was an array object so I could do the following treating the array as an object... however, that does not seem to be a possibility.

Code:
Sub SimplyArray(strArrayName as String)
    Dim ary as Array
    Set ary = strArrayName
    ....

I am sure I am already wayyyy off base. Any help would be greatly appreciated.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Perhaps I should have titled this just addressing arrays... to simplify the question how can you address an array by using another variable (i.e. a string)?

Thanks!
 
Upvote 0
Not reall;y sure what your trying to do ,but this might help.
Code:
Private Sub CommandButton2_Click()
Dim Myarray As Variant
'Range + "A1:A10" contains numbers 10 to 20
Myarray = Range("A1:A10")
Call MySub(Myarray)
End Sub
Sub MySub(mRay)
'Transfer array to sub
MsgBox mRay(3, 1) ' Result should be "12"
End Sub
Mick
 
Upvote 0
Thanks for your help MickG!

So I see now that I can pass it without declaring it as anything... awesome!

And it all sticks to my global!!!! You Rock. :)

Thanks :D

Not reall;y sure what your trying to do ,but this might help.
Code:
Private Sub CommandButton2_Click()
Dim Myarray As Variant
'Range + "A1:A10" contains numbers 10 to 20
Myarray = Range("A1:A10")
Call MySub(Myarray)
End Sub
Sub MySub(mRay)
'Transfer array to sub
MsgBox mRay(3, 1) ' Result should be "12"
End Sub
Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top