Need VBA code to make One listbox show same selected values on secondary listbox

atf32

Board Regular
Joined
Apr 13, 2011
Messages
157
Need help. On one worksheet I have one listbox that holds several different country names. This listbox allows me to select multiple countries at once. On another worksheet, I have another listbox that holds the same list of counties as in the first listbox. I would like to set it up so that when I select the countries in one of the listbox's, the same selected items will show up on the other listbox as highlighted, and vice versa, as if I selected the same countries on the other listbox.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Where did the ListBox come from... the Forms toolbar or the (ActiveX) Control Toolbox toolbar?
 
Upvote 0
This event code appears to keep ListBox2 at the same selections as ListBox1...
Code:
Private Sub ListBox1_Change()
  Dim X As Long
  With Worksheets("Sheet1")
    For X = 0 To .ListBox1.ListCount - 1
      .ListBox2.Selected(X) = .ListBox1.Selected(X)
    Next
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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