Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Advice on List Box Search


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Advice on List Box Search

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Advice on List Box Search

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Advice on List Box Search

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Advice on List Box Search

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Advice on List Box Search

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
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
big list. Need advice for a new user of how to streamline it Kent New Users to Excel 2 April 1st 08 09:23 PM
list, search, and display Richard[_2_] Excel Worksheet Functions 2 May 5th 07 06:05 PM
Column list search JRIVERA77 Excel Worksheet Functions 2 February 8th 06 06:32 PM
Advice on Approach to Convert List of Dates into a Calender format Andibevan[_4_] Excel Programming 0 November 23rd 05 02:55 PM
Search in a list. comotoman Excel Discussion (Misc queries) 3 September 19th 05 07:22 PM


All times are GMT +1. The time now is 05:08 AM.

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"