Frankie
Frankie

Reputation: 37

Adding a dictionary to array

I'd like to go through list in Excel and assign the values to dictionary. The the dictionary will be put into list. This will happen until the cells in the column are blank. As a result of entire function, the array of dictionaries will be returned.

 Function CreateArrayofDicts()
    Dim catlist As Variant
    Dim catparams() As Variant
    Dim ChartParamsDict As Dictionary
    Dim k As Long
    catlist = ArrayProblemsCat()

    i = 1

    Do Until IsEmpty(Cells(i, 1))
        Set ChartParamsDict = New Scripting.Dictionary
        For j = 0 To UBound(catlist)
            Debug.Print Cells(i, 1)
            If Cells(i, 1) = catlist(j) Then
                Debug.Print 5
                ChartParamsDict.Add Key:="Cells(1,2)", Item:=Cells(i, 2)
                ChartParamsDict.Add Key:="Cells(1,3)", Item:=Cells(i, 3)
                ChartParamsDict.Add Key:="Cells(1,4)", Item:=Cells(i, 4)

                ReDim Preserve catparams(k)
                catparams(k) = ChartParamsDict ' issues is here
                k = k + 1
                Debug.Print ChartParamsDict
            End If

        Next j



    i = i + 1
    Loop
    CreateArrayofDicts = catparams
End Function

Upvotes: 0

Views: 74

Answers (1)

Tim Williams
Tim Williams

Reputation: 166196

Your are missing Set on the problem line.

Set catparams(k) = ChartParamsDict

Upvotes: 1

Related Questions