linking 2 listboxes together so they sync

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
hi just wondering if it is possible to sync 2 listboxes together in code, as i have 14 columns and listboxes only can list 10 please see below the code i have at moment
VBA Code:
Private Sub ListBox1_AfterUpdate()
   Me.TextBox1.Value = Me.ListBox1.Column(0)
    Me.TextBox2.Value = Me.ListBox1.Column(1)
     Me.TextBox3.Value = Me.ListBox1.Column(2)
     Me.TextBox4.Value = Me.ListBox1.Column(3)
     Me.TextBox5.Value = Me.ListBox1.Column(4)
     Me.TextBox6.Value = Me.ListBox1.Column(5)
     Me.TextBox7.Value = Me.ListBox1.Column(6)
 End Sub
Code:
Private Sub ListBox2_AfterUpdate()
   Me.TextBox8.Value = Me.ListBox2.Column(0)
    Me.TextBox9.Value = Me.ListBox2.Column(1)
     Me.TextBox10.Value = Me.ListBox2.Column(2)
     Me.TextBox11.Value = Me.ListBox2.Column(3)
     Me.TextBox12.Value = Me.ListBox2.Column(4)
     Me.TextBox13.Value = Me.ListBox2.Column(5)
     Me.TextBox14.Value = Me.ListBox2.Column(6)
 End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
hi just wondering if it is possible to sync 2 listboxes together in code, as i have 14 columns and listboxes only can list 10 please see below the code i have at moment
VBA Code:
Private Sub ListBox1_AfterUpdate()
   Me.TextBox1.Value = Me.ListBox1.Column(0)
    Me.TextBox2.Value = Me.ListBox1.Column(1)
     Me.TextBox3.Value = Me.ListBox1.Column(2)
     Me.TextBox4.Value = Me.ListBox1.Column(3)
     Me.TextBox5.Value = Me.ListBox1.Column(4)
     Me.TextBox6.Value = Me.ListBox1.Column(5)
     Me.TextBox7.Value = Me.ListBox1.Column(6)
End Sub
Code:
Private Sub ListBox2_AfterUpdate()
   Me.TextBox8.Value = Me.ListBox2.Column(0)
    Me.TextBox9.Value = Me.ListBox2.Column(1)
     Me.TextBox10.Value = Me.ListBox2.Column(2)
     Me.TextBox11.Value = Me.ListBox2.Column(3)
     Me.TextBox12.Value = Me.ListBox2.Column(4)
     Me.TextBox13.Value = Me.ListBox2.Column(5)
     Me.TextBox14.Value = Me.ListBox2.Column(6)
End Sub
I have put in a spin code with the code below but still not linking up together
VBA Code:
Private Sub SpinButton1_Change()
If ScrollBar1.Value <= ListBox1.ListCount - 1 Then
    ListBox1.ListIndex = ScrollBar1.Value
    ListBox2.ListIndex = ScrollBar1.Value
End If
End Sub
 
Upvote 0
i think i have them syncing together as they do move inline with each other now but but my data in listbox2 is not going into textbox10, my data in listbox1 is going into the corrrect textboxes.
VBA Code:
Private Sub ListBox2_AfterUpdate()
ListBox1.ListIndex = ListBox2.ListIndex
Me.TextBox10.Value = Me.ListBox2.Column(0)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,271
Members
448,882
Latest member
Lorie1693

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