Return to VBA Code Examples

VBA – Populate Array with Unique Values from Column

This tutorial will teach you how to populate an array with unique values from a column in VBA.

Populate Array with Unique Values from Column

Taking a list of values from an Excel sheet into an Array is a matter of looping through the rows in  Excel and populating the array.

Consider the following list of customers in an Excel sheet.

vba array unique values 1

Using a loop, we could populate an Array in VBA.  However, a standard loop will loop through each row, including duplicate rows and you will end up with duplicate values in your Array.

The solution to to loop through the cells and populate a Collection object with the values as a collection object will not allow duplicates.  You can then use that collection object to populate your array.

Populate Array w/ Unique Values – Function

The above example showed a procedure that would perform your desired actions. But instead you might prefer a portable Function to perform the task:

To use the Function, you’ll need to call it from a Sub Procedure:

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!