The following working example code may help you.
Sub TestObjects()
Dim myDictionary As Object
Dim myRange As Range
Dim iCount As Long
If myDictionary Is Nothing Then
Debug.Print "There is NO Dictionary Object" 'Output to Immediate Window - Ctrl G in the Debugger
End If
'Create the Dictionary Object
'Reference: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_3391-Using-the-Dictionary-Class-in-VBA.html
'Reference: http://www.snb-vba.eu/VBA_Dictionary_en.html
'KEY: Item Name
'ITEM: Count
Set myDictionary = CreateObject("Scripting.Dictionary")
'myDictionary.CompareMode = vbBinaryCompare 'case sensitive
myDictionary.CompareMode = vbTextCompare 'case insensitive
If Not myDictionary Is Nothing Then
Debug.Print "There is a Dictionary Object"
End If
iCount = myDictionary.Count
Debug.Print "The Dictionary contains " & iCount & " items."
'Add values to the Dictionary
myDictionary.Add "abc", 1
myDictionary.Add "def", 888
iCount = myDictionary.Count
Debug.Print "The Dictionary contains " & iCount & " items."
Set myRange = Intersect(Range("A1:A12"), Rows(1))
If myRange Is Nothing Then
Debug.Print "Intersect(Range(""A1:A12""), Rows(1)) is Nothing."
Else
Debug.Print "Intersect(Range(""A1:A12""), Rows(1)) contains the range " & myRange.Address(False, False) '(False, False) removes '$' from Address
End If
Set myRange = Intersect(Range("A1:A12"), Rows(22))
If Not myRange Is Nothing Then
Debug.Print "Intersect(Range(""A1:A12""), Rows(22)) contains the range " & myRange.Address(False, False)
Else
Debug.Print "Intersect(Range(""A1:A12""), Rows(22)) is Nothing."
End If
'Clear Object Pointers
Set myDictionary = Nothing
Set myRange = Nothing
End Sub
Lewis
Bookmarks