I have a Worksheet_BeforeDoubleClick
event that checks to see whether a cell that's clicked has data that's in a Dictionary object, like so:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target as Range, Cancel as Boolean)
Dim dict as Dictionary
Dim df as New dictFactory
'returns a dictionary populated with all list items
Set dict=df.create
If dict.Exists(Target.Value) Then
MsgBox "Exists"
Else
MsgBox "Doesn't exist"
End If
End Sub
The problem is that this requires creating a new dictionary each time a cell is clicked. I thought it would be good to store the dictionary in a global variable in its own module, like this:
Global valuesDict As New Dictionary
and then populate it upon opening the workbook:
Private Sub workbook_open()
Dim df as New dictFactory
Set valuesDict=df.create
End Sub
But I've encountered a lot of problems with this during testing, because there are many conditions under which a global variable's value can be reset (as discussed here).
How can I store an object so that its value will be available as long as the workbook is open, throughout repeated calls to my BeforeDoubleClick
event?