Access Unique Values of property in custom object collection

rkaczano

Board Regular
Joined
Jul 24, 2013
Messages
141
Office Version
  1. 365
Platform
  1. Windows
I have a custom class and a custom collection associated with it. For the class object I have a "Asset Type" property which changes fro various instances of the object. Is there a way to find all the unique values associated with that property within the collection?

I assume at a bare minimal I can loop through all the objects in the collection and add the property values to an array of strings and then run a FindUniqueValues on that hash tag and save the revised string to a new array (See Below). However I was also wondering if there was a different way. And/or can I create that property itself in my custom collection (i.e. if clsAsset is the object, and clsPortfolio is the collection, can I create a custom property for the clsPortfolio called "AssetTypes" and perform a Count or FindUniqueValues Method on it such that Porftfolio.AssetTypes.Count returns the value I want.

'*******
Sub Test()
Dim tmparr1 () as String
Dim tmparr2 () as String
Dim tmp1 as String


tmp1 = ""

For each asset in portfolio
tmp = tmp & "|" & Asset.AssetType
Next

tmparr1 = Split (tmp, "|")

tmparr2 = FindUniqueValues(tmparr1)

End Sub
'**********
Private Function FindUniqueValues(arr as String)

Dim cUnique As Collection
Set cUnique = New Collection
Dim arr () as String

i = 0
For Each vNum In cUnique
VNum.Add (VNum,0)
Next vNum

For Each vNum In cUnique
arr(i) = vNum
Next vNum

FindUniqueValues = arr

End Sub
**************

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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