How to use a Public Array?

Engineer123

New Member
Joined
Nov 21, 2019
Messages
8
Hello, I need to have a large Public Array that is manipulated and displayed by different procedures in VBA. However, Excel is giving me an error message that says that "Arrays are not allowed as Public Members of Object Modules". Below is example code that I need to get to work...

--------------------------------------------------------

Public Matrix() As Single

Private Sub DoEverything()
'Start Here
Call SetMatrixToOnes
Call DoubleMatrix
Call DisplayMatrix
'Finished
End Sub

Private Sub SetMatrixToOnes()
Dim i, j, k As Single


ReDim Matrix(2, 2)

For i = 1 To 2
For j = 1 To 2
Matrix(i, j) = 1
Next j
Next i


End Sub

Private Sub DoubleMatrix()
Dim i, j, k As Single

For i = 1 To 2
For j = 1 To 2
Matrix(i, j) = 2 * Matrix(i, j)
Next j
Next i

End Sub


Private Sub DisplayMatrix()
Dim i, j, k As Single
Dim a, b, c As String

For i = 1 To 2
a = a & "//"""
For j = 1 To 2
a = a & " / "
a = a & Matrix(i, j)
Next j
Next i

MsgBox a

End Sub


--------------------------------------------

If anyone could help, I would greatly appreciate it.

Thank you.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
A Public variable need to be declared on top of a Standard vba module; from there it will be visible to the entire vba project
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,772
Members
449,095
Latest member
m_smith_solihull

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