A question about global/public variables

Photomofo

Active Member
Joined
Aug 20, 2012
Messages
259
Can you make an array a global variable? Let's say I have an array of Dates that run from 2000 to 2050 and I fill this array at the beginning of my program. Will all the subs and functions have access to this Dates array? I've tried this out over and over again but I can't seem to get it to work so I have to refill the Dates array in each sub and/or function that needs this info. Am I doing things wrong or is there a limitation in VBA that makes it so arrays can't be global/public?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Arrays can be public. Where did you declare the array variable?
 
Upvote 0
In a normal module, or a class/worksheet/thisworkbook module?
 
Upvote 0
It's in a normal module but it looks like I solved the problem. I was filling the arrays on startup and assuming they'd stay full. I think I need to fill the arrays each time I run the simulation. This is a lot better than filling these various data arrays 8 times per simulation. Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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