PDA

View Full Version : Populate Two Text Box using input value



hdevadiga
10-07-2012, 11:04 PM
Hi Friend,

I have a userform having two text boxe (TEXTBOX1 AND TEXTBOX2) and excel sheet too having two column mentioned below:

Emp Code Department
1001 HR
1002 Sales
1003 IT

My question is if i input the value "1001" in textbox1 than "HR" should automatically get populate in textbox2 and it get saved in sheet when i click on save button...

Bob Phillips
10-08-2012, 12:04 AM
Private Sub TextBox1_AfterUpdate()
Me.textbox2.Value = Application.VLookup(Me.TextBox1.Text, Worksheets("Sheet1").Range("A1:B20"), 2, False)
End Sub

snb
10-08-2012, 01:06 AM
You'd better use a combobox & a textbox instead:


Private Sub UserForm_Initialize()
ComboBox1.List = sheets(1).Cells(1).CurrentRegion.Value
End Sub

Private Sub ComboBox1_Change()
TextBox1.Text = ComboBox1.List(ComboBox1.ListIndex, 1)
End Sub