Selection position in a userform

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,341
I have a userform listbox for about a hundred items of which twenty fit into the listbox window, I use the below code to preselect one of the items
.lbxItems.ListIndex = ItemIndex
This highlights the selected item, but positions the items shown in the listbox with my selection being the last visible row. Typically I will want to select one of the items below the selected item and I would prefer that the selected item were shown half way down the listbox to avoid my having to scroll down to see the lower items. Is this possible?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
try selecting (itemindex + half the items count you display in the listbox) first. then unselect and select the item you really want. its a dodgy idea, but might work
 
Upvote 0
OK. I've found the answer.
.lbxItems.TopIndex = ItemIndex + 6
Oddly enough, making the top index equal to the ItemIndex doesn't put the selected item at the top. Nevertheless, I've fixed my problem, but thanks diddi for you interest.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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