Altering an array value within a dictionary

xylopagus

New Member
Joined
Nov 23, 2010
Messages
14
Okay, so I have a dictionary whose items are arrays of doubles.

I cannot figure out how to change a value of an array within my dictionary. Here's a simplified example:

Code:
Sub Test()
Dim TestDict As New Dictionary
Dim ThisArray() As Integer

ReDim ThisArray(3)

For i = 1 To UBound(ThisArray)
    ThisArray(i) = i + 14
Next i

TestDict.Add "ThisArray!", ThisArray

MsgBox TestDict("ThisArray!")(1)

TestDict("ThisArray!")(1) = 42

MsgBox TestDict("ThisArray!")(1)

End Sub
When I run that sub I expect to see 42, but I see the original value of 15.

Any assistance would be greatly appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Instead of TestDict("ThisArray!")(1) = 42 try this adjustment:
Rich (BB code):

  Dim a
  ' Read array from the dictionary item
  a = TestDict("ThisArray!")
  ' Modify it
  a(1) = 42
  ' Return back
  TestDict("ThisArray!") = a
 
Upvote 0
Instead of TestDict("ThisArray!")(1) = 42 try this adjustment:
Rich (BB code):

  Dim a
  ' Read array from the dictionary item
  a = TestDict("ThisArray!")
  ' Modify it
  a(1) = 42
  ' Return back
  TestDict("ThisArray!") = a

Thanks for the reply. This solved my problem immediately. I apologize for not posting sooner, but once I read this and tested it I knew that it would solve my problem and I could go home for the weekend!
 
Upvote 0
It’s ok, weekend is too short to notice :)
Thank you for feedback!
Vlad
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,310
Members
452,906
Latest member
phanmemchatdakenhupviral

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