dreid1011
Well-known Member
- Joined
- Jun 4, 2015
- Messages
- 3,614
- Office Version
- 365
- Platform
- Windows
Good morning,
As the title implies, I am learning how to use the dictionary object. And in doing so, my end goal is to count the number of unique entries in a 2d array with multiple criteria so that I can redim an output array to the appropriate size.
With that being said, please do not just give me the code to solve the whole problem, as that won't really help me learn.
Okay, the current issue at hand is the code below, and I am receiving an error stating that the key I am trying to add to the dictionary is already associated with it. I am watching the value of 'i' and it is at 1 when this happens. So, being that the dictionary is empty at this time, how can it already have a key associated with it? Debug highlights the line in red.
arrIn(i, 1) holds an account number. arrIn(i, 3) holds square footage.
As the title implies, I am learning how to use the dictionary object. And in doing so, my end goal is to count the number of unique entries in a 2d array with multiple criteria so that I can redim an output array to the appropriate size.
With that being said, please do not just give me the code to solve the whole problem, as that won't really help me learn.
Okay, the current issue at hand is the code below, and I am receiving an error stating that the key I am trying to add to the dictionary is already associated with it. I am watching the value of 'i' and it is at 1 when this happens. So, being that the dictionary is empty at this time, how can it already have a key associated with it? Debug highlights the line in red.
arrIn(i, 1) holds an account number. arrIn(i, 3) holds square footage.
Rich (BB code):
Sub QDelRows()
Dim dict As New Scripting.Dictionary
Dim arrIn() As Variant, arrOut() As Variant
Dim i As Long, j As Long, k As Long
arrIn = Range("A2:E11")
For i = LBound(arrIn, 1) To UBound(arrIn, 1)
If dict.Exists(arrIn(i, 1)) And dict(arrIn(i, 1)) <> arrIn(i, 3) Then
dict.Add arrIn(i, 1) & "a", arrIn(i, 3)
Else
dict.Add arrIn(i, 1), arrIn(i, 3)
End If
Next i
End Sub