Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Sort a multi column listbox in userform

I have a 4 column listbox in a userform. I would like to sort the contents
by pressing a command button above the column to be sorted. Can I do so and
if so how do I do it.

Thank You,
--
Martin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort a multi column listbox in userform

How do you populate the listbox. If using the rowsource, try sorting the
source data in the worksheet, then perhaps reassign the rowsource if
necessary.

--
Regards,
Tom Ogilvy

"Martin" wrote in message
...
I have a 4 column listbox in a userform. I would like to sort the

contents
by pressing a command button above the column to be sorted. Can I do so

and
if so how do I do it.

Thank You,
--
Martin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Sort a multi column listbox in userform

Tom,

I have a datasource of about 2000 rows referencing insurance classes.
Listbox3 consists of the major catagories of insurance ie: property,
Liability, etc (about 20 catagories). Listbox4 populates from the datasource
- listing the courses, credithours, type of instruction, and instructors,
based on the criteria selected in listbox4.

here is mycode for lisbox3_click
Private Sub ListBox3_Click()
Dim x As Integer, rw As Long, l As Integer
Dim c As Range
Dim mytest As String, mycol As Integer, mylookup As String
ListBox4.Clear
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
ListBox4.ColumnCount = 4
ListBox4.ColumnWidths = "190;40;47;14"

mytest = ListBox3.Value
mycol = ListBox3.ListIndex + 19
mylookup = "1"
With Worksheets("PC Analysis").Columns(mycol)
Set c = .Find(mylookup, LookIn:=xlValues, MatchCase:=False)
If Not c Is Nothing Then

firstaddress = c.address
Do
temp = c.address
l = Len(temp)
rw = Right(temp, l - 3)
ListBox4.AddItem (Worksheets("PC Analysis").Cells(rw, 10).Value)
ListBox4.List(ListBox4.ListCount - 1, 1) = _
Worksheets("PC Analysis").Cells(rw, 9).Value
ListBox4.List(ListBox4.ListCount - 1, 2) = _
Worksheets("PC Analysis").Cells(rw, 11).Value
ListBox4.List(ListBox4.ListCount - 1, 3) = _
Worksheets("PC Analysis").Cells(rw, 12).Value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.address < firstaddress
End If
End With
End Sub

mythought is to copy the contents of listbox4 into an array - sort it, based
on column selected - ie button above columns clear lisbox4 and repopulate it
with the sorted array. I think this would work but its pushing me.

Thanks for your thoughts
--
Martin


"Tom Ogilvy" wrote:

How do you populate the listbox. If using the rowsource, try sorting the
source data in the worksheet, then perhaps reassign the rowsource if
necessary.

--
Regards,
Tom Ogilvy

"Martin" wrote in message
...
I have a 4 column listbox in a userform. I would like to sort the

contents
by pressing a command button above the column to be sorted. Can I do so

and
if so how do I do it.

Thank You,
--
Martin




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort a multi column listbox in userform

Yes, that should work.

I have posted code in the past to sort a multicolumn 2D array on a selected
column. Search in Google Groups for this news group, and Ogilvy as author.

--
Regards,
Tom Ogilvy

"Martin" wrote in message
...
Tom,

I have a datasource of about 2000 rows referencing insurance classes.
Listbox3 consists of the major catagories of insurance ie: property,
Liability, etc (about 20 catagories). Listbox4 populates from the

datasource
- listing the courses, credithours, type of instruction, and instructors,
based on the criteria selected in listbox4.

here is mycode for lisbox3_click
Private Sub ListBox3_Click()
Dim x As Integer, rw As Long, l As Integer
Dim c As Range
Dim mytest As String, mycol As Integer, mylookup As String
ListBox4.Clear
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
ListBox4.ColumnCount = 4
ListBox4.ColumnWidths = "190;40;47;14"

mytest = ListBox3.Value
mycol = ListBox3.ListIndex + 19
mylookup = "1"
With Worksheets("PC Analysis").Columns(mycol)
Set c = .Find(mylookup, LookIn:=xlValues, MatchCase:=False)
If Not c Is Nothing Then

firstaddress = c.address
Do
temp = c.address
l = Len(temp)
rw = Right(temp, l - 3)
ListBox4.AddItem (Worksheets("PC Analysis").Cells(rw, 10).Value)
ListBox4.List(ListBox4.ListCount - 1, 1) = _
Worksheets("PC Analysis").Cells(rw, 9).Value
ListBox4.List(ListBox4.ListCount - 1, 2) = _
Worksheets("PC Analysis").Cells(rw, 11).Value
ListBox4.List(ListBox4.ListCount - 1, 3) = _
Worksheets("PC Analysis").Cells(rw, 12).Value
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.address < firstaddress
End If
End With
End Sub

mythought is to copy the contents of listbox4 into an array - sort it,

based
on column selected - ie button above columns clear lisbox4 and repopulate

it
with the sorted array. I think this would work but its pushing me.

Thanks for your thoughts
--
Martin


"Tom Ogilvy" wrote:

How do you populate the listbox. If using the rowsource, try sorting

the
source data in the worksheet, then perhaps reassign the rowsource if
necessary.

--
Regards,
Tom Ogilvy

"Martin" wrote in message
...
I have a 4 column listbox in a userform. I would like to sort the

contents
by pressing a command button above the column to be sorted. Can I do

so
and
if so how do I do it.

Thank You,
--
Martin






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
Dynamic Multi Column ListBox Ronbo Excel Programming 3 January 11th 05 07:59 PM
Multi-Column Listbox properties Otto Moehrbach[_6_] Excel Programming 1 December 5th 04 10:35 PM
populating a multi-column Listbox Tom Ogilvy Excel Programming 3 April 26th 04 08:26 PM
populating a multi-column Listbox Harald Staff Excel Programming 1 April 26th 04 08:26 PM
Date formatting in a multi column listbox Nigel Brown[_2_] Excel Programming 2 September 3rd 03 11:29 AM


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

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

About Us

"It's about Microsoft Excel"