Re: Sorting combobox elements

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Chip,

Thanks for the help. This is exactly what I was looking for, and I'm sure
I'll use your solution extensively in the future.

Ken

"Chip Pearson" wrote:


I have a page on my web site regarding sorting arrays. See
http://www.cpearson.com/Excel/SortingArrays.aspx . On that page is a
function named QSortInPlace that will sort an array in either
ascending or descending order. The code is too lengthy to post here.
You can either copy the code off the web page or download the bas
module file from http://www.cpearson.com/Zips/modQSortInPlace.zip . If
you download the zip file, save it somewhere, unzip it, and then with
your workbook open, go to VBA, then to the File menu, choose Import
File, and open the unzipped bas file named modQSortInPlace.bas. This
will create a new module in your workbook project.

Documentation is on the web page and also within the bas file.

Once you have the code, you can put the elements in the combobox into
an array, call QSortInPlace to sort the array in either ascending or
descending order, and then reload the array back into the combobox. In
the code, change "ComboBox1" to the name of your combobox.


Dim Arr() As String
Dim N As Long
With Me.ComboBox1
ReDim Arr(0 To .ListCount - 1)
For N = 0 To .ListCount - 1
Arr(N) = .List(N)
Next N
QSortInPlace InputArray:=Arr, _
Descending:=False, CompareMode:=vbTextCompare
.Clear
.List = Arr
End With

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 4 Sep 2009 10:45:02 -0700, Ken Warthen
<KenWarthen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

I have a combobox on an Excel 2007 userform to which I'd like to add the
elements of a worksheet range in a sorted order. There may be anywhere from
several hundred to a few thousand items. I'm able to add the items by
iterating through the named range, but users have now requested that the
elements be displayed in alpha or numeric order. I've looked around and
can't find any relatively simple way to do this. Any help will be greatly
appreciated.

Ken

.



Relevant Pages

  • Re: Sorting combobox elements
    ... I have a page on my web site regarding sorting arrays. ... function named QSortInPlace that will sort an array in either ... you can put the elements in the combobox into ...
    (microsoft.public.excel.programming)
  • Re: Assistance please
    ... I would appreciate some assistance please with a web site I help out with. ... The web site allows the user to select from various lists either a full list of all of the stories or a sub set of the stories based on various select statements, this works well and has been for some time. ... I was asked to add these and on the face of it, it appeared to be fairly simple but clearly the scripts needed to know which story to go to next, it could not just go to the next in the database. ... One pages where it works OK I have it,temporarily showing how big the array for this selection is, where in the array the current story is but once a user selects forward to get to a story within the records that have been deleted the array size and position within the array lose their values. ...
    (comp.lang.php)
  • Re: How to create a Multi dimensional array
    ... You could use an object with array properties. ... var listA =; ... The first combobox will be populated with the items in LIST A and the ... Create your second combobox, ...
    (comp.lang.javascript)
  • Re: Combobox an Array binden
    ... Ich habe inzwischen mit der Combobox herumgespielt. ... Auch mit dem Tabulator ist es etwas schwierig, die anderen Spalten venünftig ... die an ein Array gebunden werden kann. ... Wie binde ich den Steuerelementinhalt an eine Spalte im Array. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Assistance please
    ... I would appreciate some assistance please with a web site I help out with. ... The website is database driven with MYSQL as the back end. ... My idea was to build an array of which stories were required in the first ... // Load the memory number into the correct position within the array ...
    (comp.lang.php)