Listbox scroll

Keith.Jackson

Board Regular
Joined
Mar 31, 2005
Messages
115
I have Listbox1 and and listbox2 on the same userform.
I want Listbox2 to scroll equally as I scroll listbox1
Not just to equal the same value, since that would be Listbox2.Value= Listbox1.voalue

How can I make that happen?

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi there,

There is no event to capture the scrolling of a listbox. However, you could emulate something like it by using the Click event. Now it wouldn't work with just scrolling (sorry), but does for clicking values in the list....


<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> j <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> sVal <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> bEnd <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br>    <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ListBox1_Click()<br>    <SPAN style="color:#00007F">If</SPAN> bEnd = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> Me.ListBox1.ListCount - 1<br>        <SPAN style="color:#00007F">If</SPAN> Me.ListBox1.Selected(i) = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>            sVal = Me.ListBox1.List(i)<br>            <SPAN style="color:#00007F">For</SPAN> j = 0 <SPAN style="color:#00007F">To</SPAN> Me.ListBox2.ListCount - 1<br>                <SPAN style="color:#00007F">If</SPAN> Me.ListBox2.List(j) = sVal <SPAN style="color:#00007F">Then</SPAN><br>                    Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN><br>                    bEnd = <SPAN style="color:#00007F">True</SPAN><br>                    Me.ListBox2.TopIndex = Me.ListBox1.<SPAN style="color:#00007F">To</SPAN>pIndex<br>                    Me.ListBox2.ListIndex = j<br>                    Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN><br>                    bEnd = <SPAN style="color:#00007F">False</SPAN><br>                    <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN><br>                <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>            <SPAN style="color:#00007F">Next</SPAN> j<br>            <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> i<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> ListBox2_Click()<br>    <SPAN style="color:#00007F">If</SPAN> bEnd = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> i = 0 <SPAN style="color:#00007F">To</SPAN> Me.ListBox2.ListCount - 1<br>        <SPAN style="color:#00007F">If</SPAN> Me.ListBox2.Selected(i) = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>            sVal = Me.ListBox2.List(i)<br>            <SPAN style="color:#00007F">For</SPAN> j = 0 To Me.ListBox1.ListCount - 1<br>                <SPAN style="color:#00007F">If</SPAN> Me.ListBox1.List(j) = sVal <SPAN style="color:#00007F">Then</SPAN><br>                    Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN><br>                    bEnd = <SPAN style="color:#00007F">True</SPAN><br>                    Me.ListBox1.<SPAN style="color:#00007F">To</SPAN>pIndex = Me.ListBox2.TopIndex<br>                    Me.ListBox1.ListIndex = j<br>                    Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN><br>                    bEnd = <SPAN style="color:#00007F">False</SPAN><br>                    <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN><br>                <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>            <SPAN style="color:#00007F">Next</SPAN> j<br>            <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">For</SPAN><br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> i<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><SPAN style="color:#007F00">'////</SPAN><br><SPAN style="color:#007F00">'USED FOR TESTING PURPOSES ONLY</SPAN><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()<br>    For i = 1 To 20<br>        Me.ListBox1.AddItem i<br>        Me.ListBox2.AddItem i<br>    <SPAN style="color:#00007F">Next</SPAN> i<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>


HTH
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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