listbox form control scrollbar question

billritz

New Member
Joined
Aug 20, 2012
Messages
23
I want the scrollbar at the top, and I've seen solutions to use Sheets("Main").ListBoxes("List Box 1").scrolltop but excell says it's not a property or method. Does this only work with ActiveX? Can it be done with a simple form control? What about .topindex which the documentation from Microsoft says is a property of (inherited from) listbox. I can't get that to work either.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What documentation are you looking at?
 
Upvote 0
I don't think you can sroll a listbox (form control) programmatically.

But you can use a little hack if you just need to scroll to the top as follows:

Code:
Sub test()

    Dim list() As Variant
    
    With ActiveSheet.ListBoxes(1)[COLOR=#008000][B] '<== change listbox index or name as needed.[/B][/COLOR]
        list = .list
        .RemoveAllItems
        .list = list
        .Selected = 1
    End With

End Sub
 
Last edited:
Upvote 0
Thanks for the great idea Jaafar! I didn't think about removing all items. Then, when it loads, the scrollbar initializes to the top, which is exactly what I wanted it to do.
In workbook_open I'm initializing the listbox to a sheet the superuser maintains, so I just made sure .RemoveAllItems was just before I loaded it.
It works great, and looks better for the users. Thanks again!

Sheets("Main").Activate
ActiveSheet.Shapes("List Box 1").Select
With Selection
.RemoveAllItems
.ListFillRange = "Picklist!$A$2:$A$" & Range("Picklist!A1048576").End(xlUp).Row
.LinkedCell = ""
.MultiSelect = xlExtended
.Display3DShading = True
End With
 
Upvote 0
What exactly do you mean by 'scrollbar at the top'?

Do you mean you want the first item in the list selected?
 
Upvote 0
I meant just that - I wanted the scrollbar at the top, regardless of what was selected. One user selected the top row, then scrolled down to the bottom and selected something else. He saved it like that, and the next user opened it, saw the selections he wanted, picked a couple with CTRL, ran it, and of course got data for the top one which was out of sight. I just added stuff in the workbook_open ti re-init each time it opens (see above) and took Jaafar's idea to clear it out first, which causes the scrollbar to init up at the top, even with nothing selected.

Thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,171
Members
452,615
Latest member
bogeys2birdies

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