Using a dictionary object in Excel VBA

I'm struggling to get the Dictionary object to work in order to return the economic details of the selected reference number.

eg. However, I have below the reference numbers and corresponding values, but I'm not sure if I can achieve this using the Dictionary object, and an alternative, the sentence will be highly appreciated.

Ref No  Amount Price   Year
IB1232  1000   1.23    2011
IB1231  1000   3.23    2011
IB1233  1000   3.43    2011
IB1234  1000   3.43    2011

I thought that I could achieve by forming a key and a value for reference and the details corresponding to them, but I could not achieve.

+5
source share
2 answers

, VBA, Collection VBA (, , Ditionary, ).

, , , {1000,1.23,2011} "IB1232". , , :

Dim coll as new Collection
Dim data as new Collection

data.Add 1000
data.Add 1.23
data.Add 2011

coll.Add data, "IB1232"

, (Collection)

Debug.Print coll.Item("IB1232")(1) 'Prints 1000
Debug.Print coll.Item("IB1232")(2) 'Prints 1.23
Debug.Print coll.Item("IB1232")(3) 'Prints 2010

+12

@das_weezul

Dictionary VBA ( , ). , , , .

@Sky Cobb

, . , , , .

+14

All Articles