Changing array values in a VBA dictionary Changing array values in a VBA dictionary vba vba

Changing array values in a VBA dictionary


It seems you'll need yet to set another var to update the array value.

mArray = mydict.Item(1)mArray(1) = 34mydict.Item(1) = mArray


I created a Procedure to solve the same issue, so I could keep it as a "oneliner":

Private Sub pReplaceDicArray(Dic As Object, kEy As Variant, Element As Integer, NewValue)    Dim tempArray As Variant    tempArray = Dic(kEy)    tempArray(Element) = NewValue    Dic(kEy) = tempArrayEnd Sub' call as:' Call mReplaceDicArray(Dic, "A", 1, 8)


I would have written this answer as a comment to Mr. Irizarry's answer, but I'm not allowed. Anyway.... I tried writing that last line of code (below) to assign the array to the first item of the dictionary, but it didn't work. The array in that item remained as it was before.

mydict.items(1) = mArray

Based on what I read elsewhere, it seems to have to do with the instance of the dictionary you're calling upon. I changed it to the following line and it worked.

mydict(mydict.keys(1)) = mArray

I'm still not sure why that is the case, but there it is.