Item keys in collections

Xmarksthespot

New Member
Joined
Jan 21, 2017
Messages
7
I have a collection (colA) that has a first item of (It) with a key of (" Ke")
I want to pass this item AND its key to a second collection (colB)
But.... using
colB.Add ColA(1) or colB.Add Col("Ke") only passes the item to the second collection and not its key.
Is there any way I can pass the value and its key to a different collection.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I think you'll need to use a Dictionary object instead...

Code:
Sub test()

    Dim oDic1 As Object
    Dim oDic2 As Object
    
    Set oDic1 = CreateObject("Scripting.Dictionary")
    Set oDic2 = CreateObject("Scripting.Dictionary")
    
    oDic1.Add "Key1", "Item1"
    oDic1.Add "Key2", "Item2"
    'etc
    '
    '
    '
    
    oDic2.Add oDic1.keys()(0), oDic1.items()(0)
    
    MsgBox "First key = " & oDic2.keys()(0) & "; First item = " & oDic2.items()(0), vbInformation
    
End Sub

Hope this helps!
 
Upvote 0
I want to pass this item AND its key to a second collection (colB)
But.... using
colB.Add ColA(1) or colB.Add Col("Ke") only passes the item to the second collection and not its key.
Is there any way I can pass the value and its key to a different collection.

Hi
Welcome to the board

You are not passing the key in the examples that you posted.

Try:

Code:
ColB.Add ColA("Ke"), "Ke"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,577
Messages
6,173,163
Members
452,503
Latest member
AM74

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