How to Populate Listbox and Textboxes with Excel data using VBA
A question asked by one of our website visitors:
How to populate a list box and text boxes using data from an Excel worksheet using VBA. I have a user form with an optionbutton and 2 text boxes.
(1) Once I click on the option button ‘fans’ I wish that my list box gets populated with data from the ‘fans’ column.
(3) When I select a model I wish that the diameter of the fans and their wattage appears in the corresponding text boxes.
How can this be done quickly and easily?
Code for the optionbutton:
Private Sub OptionButton1_Change()
Me.ListBox1.RowSource = “A2: A5”
Code for the Listbox:
Private Sub ListBox1_Change()
TextBox1.Value = Application.VLookup(Me.ListBox1, Sheets(“Sheet1”).Range(“A:C”), 2, False)
TextBox2.Value = Application.VLookup(Me.ListBox1, Sheets(“Sheet1”).Range(“A:C”), 3, False)
Code for the commandbutton:
Private Sub CommandButton1_Click()
Watch the video (21 MB) below to see the solution: