I am having difficulties in trying to understand the following code. I found it here in the following link: vba: get unique values from array
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
'Set d = New Scripting.Dictionary
Dim i As Long
For i = LBound(myArray) To UBound(myArray)
d(myArray(i)) = 1
Next i
Dim v As Variant
For Each v In d.Keys()
'd.Keys() is a Variant array of the unique values in myArray.
'v will iterate through each of them.
Next v
EDIT: I quite understand the whole code but I could not understand the last section being
Dim v As Variant
For Each v In d.Keys()
'd.Keys() is a Variant array of the unique values in myArray.
'v will iterate through each of them.
Next v
and I cannot understand this line
d(myArray(i)) = 1
EDIT: I am looking for a code that executes the same objective but I would rather want to understand fully what I am applying than just copy and paste something that I do not understand.
More specifically, there are several elements in the macro that I am constructing and this one is among the ones I am looking for.
- As first objective I need to find the duplicates in my dataset
- After finding the duplicates I need to count how duplicates there are if there are 4 duplicates row my item is complete,
- Then, if there are more than 4 duplicates, I need to transfer the duplicates to another sheet and store them there
- On the other hand, if there are less than 4 duplicates, I would need to find such items and try to match these items with an inventory to try to find out the remaining elements in order to stack a full set of 4 elements.
This macro will serve me to fulfill point 4. Once I identify the items that have less than 4, I need to find such items and try to match them with the ones that I have in another sheet. I need to do so with the code above as I would rather use an array in a macro than functions in excel itself in order to avoid confusion to the user with phantom figures.