Find an item in a collection

Darren Bartrup

Well-known Member
Joined
Mar 13, 2006
Messages
1,297
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I'm having fun with collections. You know, the same kind of fun you have when you have to have a wisdom tooth out at the dentist.

I have set up a collection which contains two items. Each item contains 10 values.

In the locals window it looks like:
colQuestions
Item 1
Item 1(1) 213
Item 1(2) 340
Item 1(3) 565
Item 1(4) 65
Item 1(5) 3
.
.
.
Item 2
Item 2(1) 237
.
.
.


colQuestions.Count returns 2
ubound(colQuestions.Item(1)) returns 10

How would I return a certain value from these collections using both these methods as examples:
Return element 4 from Item 1
Return an element from Item 2 using the Key name.

Any help is greatly appreciated.

Darren.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Depending on your key:
Code:
   Debug.Print colQuestions(1)(4)
   Debug.Print colQuestions("item 2")(6)
 
Upvote 0
Thanks for that Rory.

I can't believe it was that easy.
I've been trying:
Code:
colQuestions.Item(1).Item("Essex")
and many variations.

It's not quite working as I hoped - the key references the two items and not the elements of the array within each item.
Nevermind though, I've got a workaround.

Darren.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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