linking 2 listboxes together so they sync

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,084
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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,084
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
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,084
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
 

NoSparks

Well-known Member
Joined
Mar 15, 2013
Messages
1,275
Office Version
  1. 2010
Platform
  1. Windows
as i have 14 columns and listboxes only can list 10
Using listbox1.list = WhatEverRange.Value you can have more than that.
This site may be of interest to you.
 

Forum statistics

Threads
1,148,249
Messages
5,745,619
Members
423,963
Latest member
Rayds

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
Top