VBA Adding a class to a collection [duplicate]
I have a class module called Holding. In it are several public variables. My code is this:
Dim holdings as Collection
Dim h as Holding
Set holdings = new Collection
For i = 1 to last
Set h = new Holding
h.x = y
'... etc
holdings.Add(h)
Next i
This gives me error "object doesnt support this property or method" on the holdings.Add(h)
line, but everywhere I look, it gives this exact example of how to achieve this. What am I missing?
Remove the parentheses.
holdings.Add h
Otherwise you are trying to add to the collection the value of the default property of your Holding
instance, and it doesn't have a default property.