Storing Dictionary in cell

PeterBunde

New Member
Joined
Dec 7, 2016
Messages
45
Fellow passionate colleagues!

My code populates a Dictionary type variable. Later on, an event handler (when selecting a particular cell) needs access to that Dictionary. But how do I store it meanwhile? Is there a clever way to write it into a cell in some formate, then load it back into a dictionary?

BW Peter Bunde Hansen
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Make the dictionary a public member of the worksheet class that's going to use it by putting it at the top of code, outside of any functions or subs. For example:

Code:
Public MyDictionary As Object
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

' Some code here

End Sub

When populating the dictionary, be sure to qualify it using the sheet name, for example:

Code:
Public Sub SetUpDictionary()

Set Sheet1.MyDictionary = CreateObject("Scripting.Dictionary")
'...

End Sub

WBD
 
Upvote 0
Hello WBD

Thanks for the answer; every time I generate my sheet, the old sheet is deleted and a new is inserted (with the same ). Does that conflict with your statement "Make the dictionary a public member of the worksheet"?

BW Peter Bunde Hansen
 
Upvote 0
In which case you'll need to make the dictionary a public member of a module. E.g. in Module1:

Code:
Public MyDictionary As Object
Public Sub SetUpDictionary()

Set MyDictionary = CreateObject("Scripting.Dictionary")

End Sub

Then refer to it like this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Module1.MyDictionary.Exists(Target.Value) Then MsgBox "Cool!"

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,800
Members
449,127
Latest member
Cyko

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