Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi, I'm using a list box with multi columns as a method of display. The list box has a tabstrip and it's click event sorts by that column. The list box source is a worksheet. As the columns are sorted I'd like to keep the selected item highlighted. The following is done before the sort. x = List1.ListIndex List1.BoundColumn = 2 m$ = List1 List1.BoundColumn = 3 m$ = m$ & List1 List1.BoundColumn = 4 m$ = m$ & List1 After the sort I'd like to set list index to the 'same' row. What is the best way to do this? I can only think of a line by line search looking for a match for m$. But this doesn't seem very efficient. I may also be doing this all completely the wrong way. Thanks - Kirk |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could try something like this.
Add a further column to your data and just add an incrementing value to each row (1, 2, 3 etc.) Add that extra column to the RowSource of the Listbox (but don't increase your columncount, then it won't show). Save the listindex before sorting, then use that to match in the new column after sorting to calculate what the listindex should now be. For instance, suppose you have two columns of data, add a third (C) with the incrementing number. Then something like this in the sort routine Private Sub cmdOK_Click() Dim iSelected As Long Dim iRow As Long If Me.ListBox1.ListIndex < -1 Then iSelected = Me.ListBox1.ListIndex + 1 End If With Worksheets(1) .Columns("A:C").Sort Key1:=.Range("A1"), _ Order1:=xlAscending, _ Header:=xlNo If Me.ListBox1.ListIndex < -1 Then iRow = Application.Match(iSelected, .Columns("C"), 0) Me.ListBox1.ListIndex = iRow - 1 End If End With End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "kirkm" wrote in message ... Hi, I'm using a list box with multi columns as a method of display. The list box has a tabstrip and it's click event sorts by that column. The list box source is a worksheet. As the columns are sorted I'd like to keep the selected item highlighted. The following is done before the sort. x = List1.ListIndex List1.BoundColumn = 2 m$ = List1 List1.BoundColumn = 3 m$ = m$ & List1 List1.BoundColumn = 4 m$ = m$ & List1 After the sort I'd like to set list index to the 'same' row. What is the best way to do this? I can only think of a line by line search looking for a match for m$. But this doesn't seem very efficient. I may also be doing this all completely the wrong way. Thanks - Kirk |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Sat, 17 Mar 2007 04:52:22 -0000, "Bob Phillips"
wrote: Hi Bob, Thanks for that brilliant suggestion. I've got it working with one small issue - about 10% of the time nothing is selected. I added MsgBox List1.ListIndex into the last If Statement and it does have the right row number. Any thoughts on that ? Thanks - Kirk |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Not off the top Kirk.
It might be the data, it might be frequency, a bit hard to say. Could you mail your workbook to me to look at, preferably with a set of repeatable actions to demonstrate it. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "kirkm" wrote in message ... On Sat, 17 Mar 2007 04:52:22 -0000, "Bob Phillips" wrote: Hi Bob, Thanks for that brilliant suggestion. I've got it working with one small issue - about 10% of the time nothing is selected. I added MsgBox List1.ListIndex into the last If Statement and it does have the right row number. Any thoughts on that ? Thanks - Kirk |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Mon, 19 Mar 2007 00:45:11 -0000, "Bob Phillips"
wrote: It might be the data, it might be frequency, a bit hard to say. Could you mail your workbook to me to look at, preferably with a set of repeatable actions to demonstrate it. OK Bob. How do I mail it to you ? Thanks - Kirk |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
bob dot NGs at gmail dot com
do the obvious -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "kirkm" wrote in message ... On Mon, 19 Mar 2007 00:45:11 -0000, "Bob Phillips" wrote: It might be the data, it might be frequency, a bit hard to say. Could you mail your workbook to me to look at, preferably with a set of repeatable actions to demonstrate it. OK Bob. How do I mail it to you ? Thanks - Kirk |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
big list. Need advice for a new user of how to streamline it | New Users to Excel | |||
list, search, and display | Excel Worksheet Functions | |||
Column list search | Excel Worksheet Functions | |||
Advice on Approach to Convert List of Dates into a Calender format | Excel Programming | |||
Search in a list. | Excel Discussion (Misc queries) |