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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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