I’m writing an Excel macro, and I’m having trouble clearing a Scripting.Dictionary object:
Dim test As Integer
test = CompListDict.Count
CompListDict.RemoveAll
Set CompListDict = Nothing
Set CompListDict = CreateObject("Scripting.Dictionary")
Dim test1 As Integer
test1 = CompListDict.Count
Before I do this, I add items to the dictionary, and then i try to clear it, but test1 will equal test and equal the nr of objects I’ve added.
What am I doing wrong ?
Thank you!
If I run the following macro on my workstation, it works :
After running it, test1 equals 0, and test equals 1.
Make sure you have Option Explicit enabled, and that you don’t have any typos in your variable names.
Also, make sure you don’t have an “On Error Resume Next” statement, as it will hide away errors in your code. Try placing “On Error Goto 0” before your code snippet, so that Excel will display any error message.
Since you’re setting the variable value to Nothing, and assigning it a new dictionnary object, it should be impossible that it retains the previsouly stored values.
I also tried running the following code, and it also gives the same results:
Hope that helps…