Populate Listbox and Textboxes with Excel data using VBA

Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010

Home



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"
End Sub

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)
End Sub

Code for the commandbutton:
Private Sub CommandButton1_Click()
End
End Sub

Watch the video (21 MB) below to see the solution:





Home
Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010