Working in Excel VBA, and I am trying to initialize an array of several objects of the class "CUserType", but I am having some trouble. I tried doing this in a loop, like this:
For count = 1 To size
Dim myArray(count) As CUserType
Next
However, it looks like VBA wants the array index to be a constant integer.
Now I am trying to do it with a separate function, like this:
Sub ititUsers(num As Integer)
Dim myArray() As CUserType
Redim myArray(1 to num)
If num = 1 Then
Dim myArray(1) As CUserType
ElseIf num = 2 Then
Dim myArray(1) As New CUserType
Dim myArray(2) As New CUserType
ElseIf num = 3 Then
Dim myArray(1) As New CUserType
Dim myArray(2) As New CUserType
Dim myArray(3) As New CUserType
.
.
.
End Sub
But of course this is both tedious and wasteful. I am new to this, so I know I am probably missing something. Any help?
Thank you!