Make the selected row of a ListBox the top row viewed

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
I would like to have the currently selected item in a ListBox move to the top of the list box. The source is a sorted column of a table.

The ListBox is both a selection tool and is updated when the forms CurrentRecord changes.

Does anyone know how to control the visible position of row items in a ListBox?
Or, make the current selection the top visible row in a listbox?

Private Sub Form_Current()
Dim myWord As Variant

'Select found record in ListBox after "Find."
If upDateList = "T" Then
Me.Word.SetFocus
myWord = Me![Word].Text
Me.ListBox_Lookup.Value = myWord
End If

upDateList = "F"
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The information in a listbox depends on the RowSourceType.

1. Table/Query

As the information in the listbox is (or should be) based on a query, thedata in the listbox is represented as it is sorted within the query. Therefore, you can't immediately move the selected value to the top of the listbox.

You can workaround this by introducing a new field (Yes/No) to the queried table of the listbox's RowSource. Once selected, I'd ensure that the checkbox was set to Yes and an update query setting all the other checkboxes in that field were set to No. Now you can sort first on True/False, and then on the normal sort criteria of the original RowSource. On the AfterUpdate event of the listbox be sure to Requery to see the change occur.

2. Value List

Simply rebuild the Value List.
 
Upvote 0
Thanks, My list box is populated by a Column of a sorted Table, not a Query. I will try an API to modify the properties of the ListBox to include a View property [which should have been included by MS in the first place!].
 
Upvote 0
Another option could be to fill the list by code but this could be slow for a big list.

See the "Add "(All") to list" function that come in the "Developer Solutions" database.

HTH

Peter
 
Upvote 0

Forum statistics

Threads
1,221,707
Messages
6,161,416
Members
451,705
Latest member
Priti_190

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top