Sort combobox vba

Sort combobox vba

nucliabrasil
Advocate Advocate
2,537 Views
2 Replies
Message 1 of 3

Sort combobox vba

nucliabrasil
Advocate
Advocate

Hello!
How to sort the items listed in a combobox in vba?
Thank you very much in advance.

0 Likes
Accepted solutions (1)
2,538 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

Unfortunately, combobox in VBA does not come with a sort feature you can use. You need to sort the data list before adding them to the combobox. if the dropdown list has to sort differently at run time, you need to clear the combobox, resort the data list and re-add them back to the combobox. 

Since the built-in data structure in VBA (array, collection) also do not have built-in sorting method, you need to write your own sorting code. Fortunately there are a lot code samples on the net for various sorting algorithms that you can directly use, or with minor modification.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

nucliabrasil
Advocate
Advocate
Accepted solution

Thank you Norman for the attention!
But today I managed to solve this.
The code is not mine, but I adapted it to my need
and gave it right. If any companions need you can adapt to your need as well. This is the link:

 

https://forums.autodesk.com/t5/visual-basic-customization/sorting-list-boxes-in-vba/m-p/301704#M4798

 

Regards!

0 Likes