I have a VBA Sub that create and handle an array:
Option Base 1
Public myArr(20, 10) As Variant
Sub Stackoverflow()
Dim x, y As Integer
'Put some values to array (only in the first 15 rows)
For x = 1 To 15
For y = 1 To 10
myArr(x, y) = (x * y + 8)
Next y
Next x
End Sub
Then there is a userform with a commandbutton that should be able to handle the array myArr.
Private Sub commandbutton_Click()
Dim a, b As Integer
'Put some other values in the remaining rows
For a = 16 To 20
For b = 1 To 10
myArr(a, b) = (a * b + 3)
Next b
Next a
End Sub
How can I pass the array to the userform? And how the Sub can view the updated array?
Thanks
Your code worked perfectly for me once I had completed it. I can only assume you do not know how to call the userform.
I copied your
Stackoverflow()to a module without changes.To the same module I added:
I created a user form and did not change the default name from UserForm1. I added a button, named it
commandbuttonand copied your code to the form’s code area. Before theEnd Sub, I addedUnload UserForm1to close and exit the form.I ran Main and the following was output to the immediate window:
I have not checked the values but I assume they are correct.