Combo Box - Now populated with unique values but how to best sort them alphabetically ??

R

Rob W

Greetings,

I had an issue of how to populate my combo box with unique values only,
after some research I discovered collections and how they dont allow
duplicate values and I could simply skip the error to achieve the results I
wanted.

However how can I modify the code to sort the values in the collection
(Unique) in alphabetical order?

I've seen some complex looking loops based on the old bubble sort routines
that I wrote many many moons ago, but wondering what other peoples solutions
would be?
Any assistance would be appreciated.

Cheers
Rob


'Populate combo box with unique Diagnosis values
With comboDiagnosis

Dim Uniques As New Collection
Dim unsorted As Boolean
On Error Resume Next

For Each cell In wsData.Range("G2:G" &
lRowEnd).SpecialCells(xlCellTypeConstants, 2)
Uniques.Add cell.Value, CStr(cell.Value)
Next cell

For Each Item In Uniques
comboDiagnosis.AddItem Item
Next Item

End With
 
R

Rob W

Thanks I spotted your previous reply to my other question too.

Adapted the code and it all works great, very happy.

Thanks.
Rob W
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top