Give this a try
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 Scripting.Dictionary
Dim i As Long, j As Long, k As Long, y As Long
Dim lRows As Long
Dim x As Variant
'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
Set dic(x) = New Scripting.Dictionary 'Set your dictionary ouside the loop
For Each ws In wb.Worksheets
If Left$(ws.Name, 1) = "d" Then
lRows = ws.Cells(Rows.Count, 1).End(xlUp).Row 'Last row
For k = 1 To lRows
dic(ws.Cells(k, 1)) = ws.Cells(k, 2)
Next k
End If
Next ws
x = dic.Items
For y = 0 To UBound(x)
Debug.Print x(y)
Next y
'Tidy up
'Erase arrays
'Destroy objects
Set wb = Nothing
'Excel environment
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
End With
End Sub
Bookmarks