1
votes

Ive set up a custom collection on VBA, in order to store several objects from the worksheet & loop over the items to create a ppt presentation.

Unfortunately ive hit a snag in creating the custom collection: ive set it up as follows and get an Object variable or with block variable error

Sub Funds()
Dim Funds As Collection
Dim V As Fund
Set V = New Fund

V.FundID = "V1"
V.Title = "Profile_FactSheet_Title_En"
V.Fund_MER = "V1_Mer_En"
V.Fund_Yield = "V1_Yield_End"
V.Asset_Alloc = "V1_assetAlloc_En_SourceData"
V.Asset_Alloc2 = "AAV1EN"
V.Asset_Alloc3 = "FIV1EN"
V.Asset_Alloc4 = "FIMAV1EN"
V.Title_2 = "Profile_FactSheet_Title_En"
V.Trailing = "RetV1TrailingEN"
V.Calendar = "RetV1CalendarEN"

Funds.Add V, V.FundID

End Sub

As i look over this i think everything is set properly but i still get that error.

In addition i have a class module for the objects in the collection as such:

Option Explicit

Public FundID As String
Public Title As String
Public Fund_MER As String
Public Fund_Yield As String
Public Asset_Alloc As String
Public Asset_Alloc2 As String
Public Asset_Alloc3 As String
Public Asset_Alloc4 As String
Public Title_2 As String
Public Trailing As String
Public Calendar As String

Any help on this would be greatly appreciated!!

1
You need to New your Funds collection. - Brian M Stafford

1 Answers

3
votes

Dont give your collection and sub the same name (Funds). And you either need to do:

Dim Funds As Collection
Set Funds = New Collection

OR

Dim Funds As New Collection