VBA – Remove Duplicates From Array

This tutorial will teach you how to remove duplicates from an Array in VBA.

Remove Duplicates

The easiest way to remove duplicates from a VBA Array is to assign the array values to a VBA Collection and then pass the values back to an Array. Collections don’t allow duplicate values and thus using a Collection, we can remove duplicates from an array.  We’ve created a function to perform this task:

Note: In the example we forced our Array to start at 1 (not 0). If your array starts at 0 you will need to modify the code slightly.

Notice that we convert the array contents to a string. If necessary, you could convert the strings back to integers after the process is complete.

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)