Thread: Uniquenos UDF
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Bayo
 
Posts: n/a
Default Uniquenos UDF


Ron Rosenfeld wrote:
On 24 Dec 2005 21:36:41 -0800, "Bayo" wrote:

Thank you very much to both of you. I tried and kept both corrections
and both work perfect, I think it sorts according first digit, like 25
is in front of 3, it returns 1,2,25,3,35,42,5 etc...however it is still
OK after having the unique values.

Really great help and of course and excellent UDF (still have to work
on it to understand...).

Regards,

Merry X-Mas and Happy Many Years...
Bayo


The purpose of the function is to return unique values. It will work with
either numbers or non-numeric values.

The purpose of the sorting routine is NOT to be able to return the values in a
sorted order, but rather to place identical values "next to each other" so the
non-unique values can be more readily identified. Using this technique, it
happens that the values are returned in an alpha sorted order.

For this purpose the values are all handled as strings.

If you want to return the values sorted numerically (as opposed to the alpha
sort which is presently the case), you can convert the values to numbers, and
then resort.

For example: (-- marks the changed lines)

============================
...
For i = 1 To UBound(Temp)
If Temp(i) Temp(i - 1) Then
j = j + 1
ReDim Preserve Temp2(j)
-- Temp2(j) = IIf(IsNumeric(Temp(i)), Val(Temp(i)), Temp(i))
End If
Next i

-- BubbleSort Temp2

UniqueNos = Join(Temp2, ",")

End Function
============================


--ron


Thanks Ron,
That works fine when I place a comma in front of initial entry,
otherwhise, first number appears in the result and then the remaining
ones appear in sorted order.


Regards,
Baybars