Consulting

Results 1 to 3 of 3

Thread: Populate Two Text Box using input value

  1. #1

    Populate Two Text Box using input value

    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...

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Private Sub TextBox1_AfterUpdate()
    Me.textbox2.Value = Application.VLookup(Me.TextBox1.Text, Worksheets("Sheet1").Range("A1:B20"), 2, False)
    End Sub
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    You'd better use a combobox & a textbox instead:

    [VBA]
    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
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •