Obtain distinct values from array

mpothen

New Member
Joined
Jul 25, 2011
Messages
6
Is there an easy/quick way to select only distinct values from an array in VBA (I'm using Excel 2007)?

I'm hoping there's an existing method for doing this, but maybe you have to do it old school and step through the entire array, compare each, etc??

Thanks,
Mitch
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Create a Dictionary or Collection and add them one at a time. Neither object will allow a duplicate entry; you should use on error resume next for a collection, but you can use .Exists for a Dictionary.
 
Upvote 0
Thank you! Any major difference between using a dictionary or collection? I'll check them out, thanks. I've never heard of either actually, so this is a new one for me.
 
Upvote 0
Also, this begs a question.. My scenario is this:

I have a cell in Excel with names separated by a semicolon ("Bob;John;Mike;Bob" for example). I need to obtain the unique values.

What I've done is parse and load them to an array using:
Array= Split(Replace(Cells(4, "G").Value, "; ", ";"), ";")

Then I can use your idea to get the unique values.

So the question is, can I load right from the cell in the same way, forgoing the Array (reduce this process by a step)??

Like:
Dictionary = Split(Replace(Cells(4, "G").Value, "; ", ";"), ";")

or similar?

Thanks again,
Mitch
 
Upvote 0
So the question is, can I load right from the cell in the same way, forgoing the Array (reduce this process by a step)??

Like:
Dictionary = Split(Replace(Cells(4, "G").Value, "; ", ";"), ";")

or similar?
I don't think so.
 
Upvote 0

Forum statistics

Threads
1,215,632
Messages
6,125,908
Members
449,273
Latest member
mrcsbenson

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