function for Unique values in an array

ankita.sethi

Board Regular
Joined
Apr 27, 2011
Messages
58
Hi,

I have an array called "Universe", which have duplicated values.
I am trying to write a code that gives me an array which have only unique values.

Can anyone help?
 
...Can you please explain the intuition behind it?What is dictionary object?What does it do?

Hi there,

As Richard seems to be away, here would be my two-cents worth...

I am not sure what you were asking as to "intuition behind it."

You will want to read the vba Help topics for Dictionary Object and Collection Object, as well as their properties and methods. In short though, the critical thing for your current issue is that the each key in a dictionary is unique. (The item for a given key is not necessarily unique.) Thus - as you see in Richard's code, after checking to see if a key already exists, he adds the key and item if it does not.

I personally remember keys and items like words and definitions in an actual dictionary. Whilst each word (key) will only appear once, several words (keys) may have the same meaning/definition (item).

I hope that helps,

Mark
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Thank you for letting me know that helped, and of course, you are most welcome :-)

Happy coding!

Mark
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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