Dictionary Array Issues

le_vrai_homme

New Member
Joined
Nov 19, 2008
Messages
12
I'm using a dictionary object with an item that contains an Array. In trying to set the value of array elements, it does not work. It simply stays with an Empty value. Any ideas? I don't seem to have problems setting the value of other non-array items in the dictionary.

Code:
Sub test()


Dim a() As Variant
ReDim a(1 To 10)
Set dict = CreateObject("scripting.dictionary")
With dict
    .Item("Array") = a
    .Item("Array")(1) = 0.4
    MsgBox .Item("Array")(1)
End With
Set dict = Nothing


End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Perhaps this:-
Code:
Dim a() As Variant, Q
ReDim a(1 To 10)
Dim Dict As Object
Set Dict = CreateObject("scripting.dictionary")
With Dict
    .Item("Array") = a
        Q = .Item("Array")
            Q(1) = 0.4
        .Item("Array") = Q
    MsgBox .Item("Array")(1)
End With
Set Dict = Nothing
 
Upvote 0
Yes. This works. So it appears that you recall single elements of the array but can't set single elements. To set values, you must set the whole array. This is very helpful. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,301
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top