Dictionary, item, object required error

Certified

Board Regular
Joined
Jan 24, 2012
Messages
189
I am getting an object required error when I run the following code:

Code:
Sub Schedule15(theDictionary As Dictionary)


    Dim singleKey As Variant
    
    For Each singleKey In theDictionary.Keys()
    
        Debug.Print theDictionary.Item(singleKey).Country
    
    
    Next singleKey


"Country" is part of a custom class.

The code runs if I remove "Country" , listing the index.

I can't figure out why would I get an object error. I copied this code from an online tutorial and it works perfectly in the video.

https://www.wiseowl.co.uk/vba-macros/videos/vba-class-structure/dictionaries/ 21:25
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The OP solved it. From that site:

[FONT=&quot]Certified Reply to Certified[/FONT]
[FONT=&quot]08 Nov 18 at 16:50[/FONT]
[FONT=&quot]I figured it out. When I populated the dictionary, I switched the key and the item. Basically, placed the key in the item spot and the item in the key spot.

[/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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