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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,214,875
Messages
6,122,037
Members
449,062
Latest member
mike575

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