A question about global/public variables

Photomofo

Board Regular
Joined
Aug 20, 2012
Messages
240
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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Arrays can be public. Where did you declare the array variable?
 

Photomofo

Board Regular
Joined
Aug 20, 2012
Messages
240
Outside of the sub next to my Option Explicit statement.

I'll give it another try.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,730
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
In a normal module, or a class/worksheet/thisworkbook module?
 

Photomofo

Board Regular
Joined
Aug 20, 2012
Messages
240
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,124
Messages
5,640,249
Members
417,131
Latest member
Seanr19871

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
Top