You can use the AdvancedFilter function in VBA to quickly get a list of unique values from a column in Excel.
Here is one common way to do so:
Sub GetUniqueValues()
Range("A1:A11").AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range("E1"), Unique:=True
End Sub
This particular example extracts a list of unique values from the range A1:A11 and displays them starting in cell E1.
The following example shows how to use this syntax in practice.
Example: Get Unique Values from Column Using VBA
Suppose we have the following dataset in Excel that contains information about various basketball players:

Suppose we would like to extract a list of unique values from the Team column.
We can create the following macro to do so:
Sub GetUniqueValues()
Range("A1:A11").AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range("E1"), Unique:=True
End Sub
When we run this macro, we receive the following output:

Column E now displays a list of unique values from the Team column in the original dataset.
Note that the AdvancedFilter method is case-insensitive.
For example, if we had the team names “MAVS” and “Mavs” in the same column then this particular macro would only return the first of these two values to occur in the Team column since they share the exact same characters.
Note: You can find the complete documentation for the AdvancedFilter method in VBA here.
Additional Resources
The following tutorials explain how to perform other common tasks in VBA:
VBA: How to Count Cells with Specific Text
VBA: How to Count Number of Rows in Range
VBA: How to Count Unique Values in Range
Hi Zach,
Found this very useful, thank you. HOwever, I actually need to go one step further and am not sure if this is possible. To try to explain,I have a table of transactions from accounts where the different accounts are both buying and selling. Is it therefore possible from this table to get a unique list of the account names/codes where they carried out buy transactions (signified by a Buy in a buy/sell column) and also then get a separate that will also shows a unique list of accounts which have carried out Sell transactions. I can think of a workaround whereby I first create 2 separate buy and sell columns that only are each only populated with the account code where the transaction was a buy or a sell and then applying the code you have suggested above to each, but was thinking there may be a more elegant way to get the same result.
Thanks in advance,
Narendar.
Hi Narendar…Thank you for your feedback and suggestions!
It might be easier to break down into sells and buys first, then extract what you want from each, which is I think what you suggested.
Can you give a sample spreadsheet of what you would like, before and after?
It might be easier to break down into sells and buys first, then extract what you want from each, which is I think what you suggested. Can you give a sample spreadsheet of what you would like, before and after?