Looping through Object

PeterBunde

New Member
Joined
Dec 7, 2016
Messages
45
Fellow sufferers

I am doing something´like this:

Code:
inhabitants_in.Add "Norway", CreateObject("Scripting.Dictionary")

inhabitants_in("Norway").Add "Oslo", 200000

How can I best, later, do something like, to find all the countries in the root:

Code:
For each country in inhabitants_in

MsgBox("Country: " & country)

Next country

BW Peter Bunde Hansen
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
What is inhabitants_in?

A collection? A class you've created/defined yourself? A dictionary?
 
Upvote 0
Peter

That doesn't really tell us much about what type of object you are dealing with.

How are you creating an instance of the object?

What properties/methods does it have?

If I use your declaration inhabitants_in has no properties and no discernible methods.
 
Upvote 0
This is all the code you have?

Code:
Dim inhabitants_in As Object

    inhabitants_in.Add "Norway", CreateObject("Scripting.Dictionary")

    inhabitants_in("Norway").Add "Oslo", 200000
If that's so then the code will immediately error on this line.
Code:
    inhabitants_in.Add "Norway", CreateObject("Scripting.Dictionary")
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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