VBA Dictionary difference

drop05

Active Member
Joined
Mar 23, 2021
Messages
285
Office Version
  1. 365
Platform
  1. Windows
Hello, I am seeing two different things with dictionaries and was wondering what is the difference between the two and the benefit of using one over the other.

I am seeing

Dim dict as new dictionary

and

Dim dict as scripting.dictionary

what is the difference between new dictionary and scripting.dictionary and what is the benefit of using one over the other if there is? Thank you in advance
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
VBA Code:
Dim dict as scripting.dictionary

In this case, scripting is the library, dictionary is the class, and dict is the variable being declared as a dictionary object from the scripting library. Here, you'll need to create an instance of the dictionary object and assign it to dict before you can start using it. And you create an instance using the keyword New with the statement Set dict = new scripting.dictionary.

VBA Code:
Dim dict as new dictionary

In this case, the variable dict is being declared as an auto-instancing dictionary object using the New keyword. Here, you don't need to explicitly create an instance of the dictionary object. Instead, it is automatically created when it's first used. The other thing to remember about this method is that if you set dict = Nothing, dict is not actually set to Nothing. Note that the declaration does not include a reference to the scripting library since it's not strictly needed. But it could have been included.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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