Chihiro
Excel Ninja
I'm trying to add Scripting.Dictionary within another Dictionary.
This is related to Deepak's thread below.
http://chandoo.org/forum/threads/count-the-records.28411/
So, to only add unique records to each bucket, I'm using Dictionary to keep track.
However, my initial code (which is in Module1) is not dynamic at all. I'm thinking using array of bucket names to create Dictionaries in Dictionary to dynamically create and access.
Referenced below thread.
http://www.mrexcel.com/forum/excel-...basic-applications-creating-objects-loop.html
I've got to a point where I was able to add items dynamically to Dictionary. But not sure how to access the dictionary within (or to check if it's a dictionary). I was able to retrieve .Key from "myObjects", but not the data within.
Any help is appreciated. Code below and workbook attached (the code is in Module2).
FYI - Microsoft Scripting Runtime is referenced in the project.
This is related to Deepak's thread below.
http://chandoo.org/forum/threads/count-the-records.28411/
So, to only add unique records to each bucket, I'm using Dictionary to keep track.
However, my initial code (which is in Module1) is not dynamic at all. I'm thinking using array of bucket names to create Dictionaries in Dictionary to dynamically create and access.
Referenced below thread.
http://www.mrexcel.com/forum/excel-...basic-applications-creating-objects-loop.html
I've got to a point where I was able to add items dynamically to Dictionary. But not sure how to access the dictionary within (or to check if it's a dictionary). I was able to retrieve .Key from "myObjects", but not the data within.
Any help is appreciated. Code below and workbook attached (the code is in Module2).
FYI - Microsoft Scripting Runtime is referenced in the project.
Code:
Sub MakeObjects()
Dim myObjects As New Scripting.Dictionary
Dim dObject As Scripting.Dictionary
Dim darry() As String
Dim dName As Variant
Dim i As Long, j As Long, lRow As Long, cCount As Long
Dim sWs As Worksheet
Set sWs = Sheet4
lRow = sWs.Range("A" & Rows.Count).End(xlUp).Row
cCount = lRow / 100
ReDim darry(1 To cCount)
For i = 1 To cCount
darry(i) = "Bucket" & i
Next i
For j = 1 To UBound(darry)
Set dObject = New Scripting.Dictionary
dName = darry(j)
myObjects.Add Item:=dObject, Key:=dName
Next
Set dObject = Nothing
myObjects.Item("Bucket4").Add Item:=1, Key:="test"
Debug.Print myObjects.Item(3)
End Sub