Return to VBA Code Examples

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 Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!