I am seeking to loop through an array of UDTs at some other point in my code from where the UDT is initialized. I am trying to split my code along functional lines and need some UDT methods to be executed at different points within the code - for example, I would like the UDT methods to calculate some values when a "calculate values" subroutine is run, then print them when I call a print subroutine. I have included the following generic snippets of what I am attempting to accomplish:


this works:
For Each rw In Range(namedRange).Rows
i = i + 1
Set ArrayOfUDTs(i) = New UDT
Application.StatusBar = "Calling Initialization..."
Call ClassModule1.initializationMethod (Argument1, ArrayOfUDTS(i) as Argument 2)
Application.StatusBar = "Calling UDT Method..."
Call ArrayOfUDTs(i).UDTMethod(Argument1)
Next rw


This does not:
For Each rw In Range(namedRange).Rows
i = i + 1
Set ArrayOfUDTs(i) = New UDT
Application.StatusBar = "Calling Initialization..."
Call ClassModule1.initializationMethod (Argument1, ArrayOfUDTS(i) as Argument 2)
Next rw

For i = LBound(ArrayOfUDTs) To UBound(ArrayOfUDTs)
Application.StatusBar = "Calling UDT Method..."
Call ArrayOfUDTs(i).UDTMethod(Argument1)
Next i

The line:

"Call ArrayOfUDTs(i).UDTMethod(Argument1)"

generates a "Object variable or With variable block not set" error

Oddly enough, if I add each of my Array elements into a collection:

Collection.add ArrayOfUDTs(1)

then loop through each of the UDTs using the collection's functions
using the following command:

Call Collection.CollectionSubroutine1(Argument1)

where:

Public sub CollectionSubroutine1(Argument1)
For i = t to UDT.count
UDT.item(i).UDTMethod(Argument1)
next i
end sub

So this works:

For Each rw In Range(namedRange).Rows
i = i + 1
Set ArrayOfUDTs(i) = New UDT
Application.StatusBar = "Calling Initialization..."
Call ClassModule1.initializationMethod (Argument1, ArrayOfUDTS(i) as Argument 2)
Application.StatusBar = "Calling UDT Method..."
Collection.add ArrayOfUDTs(1)
Next rw

Call Collection.CollectionSubroutine1(Argument1)

this does exactly what I was looking to do initially: loop through the contents of an array of UDTs (of unknown size - the size of the array is established at run time) and execute a UDT method - in other sections of my code - not necessarily when I am initially creating the array of UDTs

Can anyone shed some light as to why I am getting the "Variable not set" error when I attempt to loop through the ArrayOfUDTs in a separate loop?