Function using dictionary to delete repeated rows in array

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
217
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

The function below deletes repeated rows in a simple array. Someone could tell me how to adjust it in order to delete a multidimension dynamic array?

Function RemoveDupesDict(arr1 As Variant) As Variant
Dim i As Long
Dim dic As Object
Set dic = CreateObject (“Scripting.Dictionary”)
With dic
For i = LBound(arr1) To UBound(arr1)
If IsMissing(arr1(i)) = False Then
.item(arr1(i)) = 1
End If
Next
RemoveDupesDict = .Keys
End With
End Function

Sub RemoveDuplicatesDemo_Dictionary()
Dim arr1() As Variant
Dim arr2() As Variant
arr1 = Array("Cow", "Cat", "Cow", "Frog", "Pig", "Cat")
arr2 = RemoveDupesDict(arr1) 'Dictionary Method
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I think you need to explain what you mean by multidimensional. Do you mean a 2D array? Then will you evaluate all columns, several or only one? Or do you just mean a 2D one-based one-column array like the one you get from copying from a worksheet e.g. Data = Range("A1:A10").

Just a Thought

You don't need to use arr2. You can just do:

VBA Code:
Sub RemoveDuplicatesDemo_Dictionary()
    Dim arr1() As Variant
    arr1 = Array("Cow", "Cat", "Cow", "Frog", "Pig", "Cat")
    arr1 = RemoveDupesDict(arr1) 'Dictionary Method
    Debug.Print Join(arr1, vbLf)
End Sub

where Debug.Print Join(arr1, vbLf) is just a simple way to display the contents of a 1D array.

And a Question

What is the following supposed to do?

If IsMissing(arr1(i)) = False Then
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,442
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top