Newbie - populate (macro) GUI from Excel cells

  • Thread starter Thread starter Bill Burke
  • Start date Start date
B

Bill Burke

Hello,

I am NEW to automating Excel. I have gone into the macro editor and am
"designing" a GUI for a large Excel spreadsheet. Right now I have one drop down
list box and several fields (text boxes). I have figured out how to
automatically populate the list box with values from one of the columns in the
spreadsheet. What I'd like to do now is: Once I select a value in the list box
(server name) I would like for the fields (test boxes on the GUI) to
automatically populate with the appropriate cell values from the row where the
server name appears. I don't know how to do this. Help!!!

Any suggestions will be greatly appreciated.

TIA,
Bill Burke
(e-mail address removed)
 
Assuming your GUI is a userform with a ComboBox called ComboBox1 and a
Textbox called TextBox1, take a look at the Change event.

Something like this should do the trick:

Private Sub ComboBox1_Change()
TextBox1.Text = ComboBox1.Value
End Sub
 
Sorry, I misread the OP as being simpler than it was.

Let's assume you populated the ComboBox with the values from column A,
in the same order as they appear on the sheet.
This leaves row 1 from the sheet in ListIndex 0 of the combobox.

The following Change event would put column B of the selected item into
TextBox1

''''''''''''
Private Sub ComboBox1_Change()
With ThisWorkbook.Sheets("Sheet1")
TextBox1.Text = .Cells(ComboBox1.ListIndex + 1, 2)
End With
End Sub
''''''''''''
Tested using the following UserForm_Initialize event:
Private Sub UserForm_Initialize()
Dim i&
With ThisWorkbook.Sheets("Sheet1")
For i& = 1 To 10
ComboBox1.AddItem .Cells(i&, 1).Value
Next i&
End With
End Sub
 
Back
Top