Using an array in another form

SirTertle

New Member
Joined
Jan 25, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Good day everyone!
I'm a little new to this whole VBA thing but I do have a couple years of coding background now, so I'm not a complete newb!

What I'm trying to do is:

User is on a userform and clicks add button
add button brings user to another userform where they fill out information
once the user submits their input the content will be saved to an array that was initialized on the first userform.

My problem is it seems VBA can't recognize the array I've declared.

On my first userform I've declared my array in the general Declarations like this:
Public UserCompletedStudiesArray As Variant
Then, I initialized the userform and ReDim the array like this:
ReDim UserCompletedStudiesArray(1 To 20, 7) As String

On my second userform I do this:
Dim i As Integer
Dim arr As Variant

arr = TrainingForm.UserCompletedStudiesArray

For i = LBound(arr) To UBound(arr)

If

code that populates the array...

End If
Exit For

Next i

However the second userform doesn't recognize the array that was created on the first userform.

If there's anyone who could give me a hand with this I would greatly appreciate that!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
i think you have to declare in on top of for example module1 as global
VBA Code:
Global UserCompletedStudiesArray()
you don't declare it public in your UF1, but you can redim it there, fill it perhaps with some data.
Later you can copy it to your "arr" in your 2nd UF.
 
Upvote 0
i think you have to declare in on top of for example module1 as global
VBA Code:
Global UserCompletedStudiesArray()
you don't declare it public in your UF1, but you can redim it there, fill it perhaps with some data.
Later you can copy it to your "arr" in your 2nd UF.
Hello and thank you for your reply!

My apologies in the delay of the response! I was actually able to figure out how to have the array the userform as a public array. On the other userform where it wasn't picking up the array I created variables to equal that array then after I reassigned that variable to the array! Still learning here, not sure if that's the best way, but it works!

thanks again for reaching out! I appreciate it!
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,726
Members
448,294
Latest member
jmjmjmjmjmjm

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