linking 2 listboxes together so they sync

Patriot2879

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

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Patriot2879

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

Watch MrExcel Video

Forum statistics

Threads
1,118,269
Messages
5,571,225
Members
412,372
Latest member
JON_ROCKS
Top