I am working on an Excel file with several subs, which are independent from each other. But they still use the same variables with the same values all the time. Therefore, I would like to define the variable globally but what I found quite easily was to only declare them globally. What do I have to do that I can also fill the variable with values straight from the beginning on? Is it possible that the variables are defined from the beginning without having to write a sub, something like the example below? (I believe that isn't possible or am I wrong?)
I would appreciate your help!
Thomas
Public s1, s2, s3 As Worksheet
Public array1, array2 As Variant
s1 = ThisWorkbook.Worksheets("Sheet 1")
s2 = ThisWorkbook.Worksheets("Sheet 2")
s3 = ThisWorkbook.Worksheets("Sheet 3")
array1 = Array(3, 5, 6, 7, 5)
array2 = Array(8, 9, 10, 11, 12)
Sub code1()
...
End Sub
Sub code2()
...
End Sub
Class_Initialize(). If your subs are intended to be used as macros, you can just use them as a "wrapper" for the class functionality.Sheet1.Fooinstead ofs1.Foo. The object model gives you those as freebies.