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 =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Thank you for letting me know that helped, and of course, you are most welcome :)

Happy coding!

Mark
 
Upvote 0

Forum statistics

Threads
1,215,640
Messages
6,125,976
Members
449,276
Latest member
surendra75

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