Thanks Mike,
Can I add a dictionary to an array
I'm getting a subscript out of range error
Seem like the code should work
Thanks
w
Option Explicit
Option Base 1
Sub LoadDictionaries()
'
'Purpose:
'Load Dictionaries
'
'References:
'---------------------------------------------
'Tools >> References >> Microsoft Scripting Runtime
'Resources:
'---------------------------------------------
'
'Date Developer Action
'---------------------------------------------
'12/14/2012 ws Created
'Initilialize
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
'Declare variables
Dim wb As Workbook
Dim ws As Worksheet
Dim dic() As Dictionary
Dim i As Integer, j As Integer, k As Integer, x As Integer, y As Integer
Dim lRows As Long
'Intialize variables
x = 1
'Object reference
Set wb = ThisWorkbook
'Count number of sheets with dictionary entries
For Each ws In wb.Worksheets
If Left$(ws.Name, 1) = "d" Then
i = i + 1
End If
Next ws
'Load dictionaries from worksheets
'Assume data starts in $A$1 on each worksheet
'In the dictionary pairs below, the key comes first, the item comes second
For Each ws In wb.Worksheets
If Left$(ws.Name, 1) = "d" Then
lRows = ws.Cells(Rows.Count, 1).End(xlUp).Row 'Last row
Set dic(x) = New Dictionary
For k = 1 To lRows
dic(x).Add ws.Cells(k, 1), ws.Cells(k, 2)
Next k
x = x + 1
End If
Next ws
For y = 1 To x
Debug.Print dic(y).Count;
Next y
'Tidy up
'Erase arrays
Erase dic()
'Destroy objects
Set wb = Nothing
'Excel environment
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With
End Sub
Bookmarks