99% of the questions on this group can be answered by anyone with zero VBA experience but with the willingness to spend a few of minutes googling around and trying out the code. This one is not. So please, I need help from someone who actually knows VBA, not newbies (like me) who need to get activity points.
I found a lot of "recipes" but nothing to actually work for my project.
I have a large project containing animations with many features and color options stored/retrieved in/from arrays.
Let's say for example that one of the arrays is: arrDog=Array("white_dog", black_dog", "grey_dog").
How can I declare and initialize this array in a SINGLE place (let's say in Module3), so that the array could be used anywhere in the workbook (both sheets and modules)?
And while: Public Const ACertainName As Double = 277 declared in a module does that just fine for all my global constants (I use these liberally and reliably),
or
Sub position_x_y(shape, x As Double, y As Double)
With ActiveSheet.Shapes.Range(Array(shape))
.Left = x
.Top = y
End With
End Sub
does the same thing for a sub (can be called from everywhere while being written in only one place - I also use these subs liberally and reliably all over the project), I couldn't figure out how to do the same thing with arrays (multidimensional constants).
Based on search results I tried :
Public arrDog() As Variant
Public Sub initialize_parameters()
arrDog=Array("white_dog", black_dog", "grey_dog")
arrCat=Array("white_cat", black_cat", "grey_cat")
End Sub
or
Public arrDog() As Variant
Public Function initialize_parameters()
arrDog=Array("white_dog", black_dog", "grey_dog")
arrCat=Array("white_cat", black_cat", "grey_cat")
End Function
I wrote the code above in Module3 while trying to call the sub/function from every single procedure where needed. I even tried to declare and initialize the array on the top of each sheet and the result was the same: a compile error, VBA not being able to find the array. The project got very large and it works just fine IF the arrays are declared in each and every procedure (which is inconvenient since you declare and initialize the same thing 20 times, let's say). Thanks.
I found a lot of "recipes" but nothing to actually work for my project.
I have a large project containing animations with many features and color options stored/retrieved in/from arrays.
Let's say for example that one of the arrays is: arrDog=Array("white_dog", black_dog", "grey_dog").
How can I declare and initialize this array in a SINGLE place (let's say in Module3), so that the array could be used anywhere in the workbook (both sheets and modules)?
And while: Public Const ACertainName As Double = 277 declared in a module does that just fine for all my global constants (I use these liberally and reliably),
or
Sub position_x_y(shape, x As Double, y As Double)
With ActiveSheet.Shapes.Range(Array(shape))
.Left = x
.Top = y
End With
End Sub
does the same thing for a sub (can be called from everywhere while being written in only one place - I also use these subs liberally and reliably all over the project), I couldn't figure out how to do the same thing with arrays (multidimensional constants).
Based on search results I tried :
Public arrDog() As Variant
Public Sub initialize_parameters()
arrDog=Array("white_dog", black_dog", "grey_dog")
arrCat=Array("white_cat", black_cat", "grey_cat")
End Sub
or
Public arrDog() As Variant
Public Function initialize_parameters()
arrDog=Array("white_dog", black_dog", "grey_dog")
arrCat=Array("white_cat", black_cat", "grey_cat")
End Function
I wrote the code above in Module3 while trying to call the sub/function from every single procedure where needed. I even tried to declare and initialize the array on the top of each sheet and the result was the same: a compile error, VBA not being able to find the array. The project got very large and it works just fine IF the arrays are declared in each and every procedure (which is inconvenient since you declare and initialize the same thing 20 times, let's say). Thanks.
Last edited: