Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Select Distinct from Array
I was looking for a simple way to remove duplicates from an array; something
that was equivalent to running a SELECT DISTINCT. I didn't find exactly what I was looking for but I found something close and modified it. Hopefully someone else will find this useful, or perhaps even improve upon it. Function DistinctArray(oInputArray, _ Optional MatchCase As Boolean = True, _ Optional OmitBlanks As Boolean = True) 'declare the variables Dim oOutputArray As Variant Dim oElement As Variant Dim oDictionary As Dictionary 'create new dictionary object 'requires Microsoft Scripting Runtime reference Set oDictionary = New Dictionary 'set case sensitivity oDictionary.CompareMode = Abs(Not MatchCase) 'load elements from array into dictionary replacing duplicates For Each oElement In oInputArray oDictionary.Item(CStr(oElement)) = oElement Next 'delete any blanks If OmitBlanks Then If oDictionary.Exists("") Then oDictionary.Remove ("") End If 'load dictionary items into new array oOutputArray = oDictionary.Items 'return the new array with distinct values only DistinctArray = oOutputArray End Function The original function can be found he http://home.pacbell.net/beban/ |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Select Distinct Maximums | Excel Worksheet Functions | |||
howto select distinct values from list | Excel Worksheet Functions | |||
Select Distinct Items in a Column | Excel Programming | |||
Using an array to select data | Excel Programming | |||
select distinct row | Excel Programming |