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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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