Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Sorting multicolumn listbox

I have a listbox on an Excel userform with two columns; storenumber and
groupname. I'm currently adding each item that meets a selected criteria as
I search through a named range. I would like to display the listbox contents
sorted by the storenumber. Any idea on how I might do this? I've seen some
sorting routines, but nothing that deals with multicolumn lists.

TIA,

Ken
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sorting multicolumn listbox

This code adds data to a userbox and then sorts the box on the 2nd column

Sub test()

'fill list box
Set Mybox = UserForm1.ListBox1
Mybox.Clear
Mybox.ColumnCount = 2
For i = 0 To 9
Mybox.AddItem i
Mybox.List(i, 1) = Chr(Asc("A") + i)

Next i

'sort list box by column 2
NumRows = Mybox.ListCount
For i = 0 To (NumRows - 2)
For j = (i + 1) To (NumRows - 1)
If StrComp(Mybox.List(i, 1), Mybox.List(j, 1), _
vbTextCompare) = 1 Then

Temp = Mybox.List(i, 0)
Mybox.List(i, 0) = Mybox.List(j, 0)
Mybox.List(j, 0) = Temp

Temp = Mybox.List(i, 1)
Mybox.List(i, 1) = Mybox.List(j, 1)
Mybox.List(j, 1) = Temp
End If


Next j
Next i

End Sub


"Ken Warthen" wrote:

I have a listbox on an Excel userform with two columns; storenumber and
groupname. I'm currently adding each item that meets a selected criteria as
I search through a named range. I would like to display the listbox contents
sorted by the storenumber. Any idea on how I might do this? I've seen some
sorting routines, but nothing that deals with multicolumn lists.

TIA,

Ken

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
multicolumn listbox Peter[_21_] Excel Programming 9 July 15th 07 06:32 PM
Multicolumn Listbox Value to Spreadsheet chris[_2_] Excel Programming 2 November 15th 06 05:49 PM
multicolumn listbox - 2002 to 97 George J[_3_] Excel Programming 2 August 18th 05 12:53 PM
Multicolumn Listbox and ordinary listbox Ron_D Excel Programming 0 June 4th 04 08:56 PM
multicolumn Listbox and textalignment John Holland Excel Programming 3 September 11th 03 01:45 AM


All times are GMT +1. The time now is 02:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"