Consulting

Results 1 to 4 of 4

Thread: Vlookup result into a textbox - Help!!

  1. #1

    Vlookup result into a textbox - Help!!

    Hi,

    I have a combobox and a text box... I want to vlookup the selected item in the combobox from a defined range(TR) and populate the textbox with the result .. I have used the below codes to no avail and nothing is populted

    1)TextBox1.Value = WorksheetFunction.VLookup(ComboBox2.Value, Range("TR"), 2, False)..

    2)TextBox1.Value = WorksheetFunction.VLookup(CLng(ComboBox2.Value), Range("TR"), 2, False)

    Please help.
    Thank you.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That looks okayish, but it is difficult to be precise as we get so little.

    What is the data involved, and where is that code, which procedure?
    ____________________________________________
    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
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If combobox data is numeric try
    [VBA]
    TextBox1.Value = WorksheetFunction.VLookup(ComboBox2.Value * 1, Range("TR"), 2, False)

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    sorry i'll be a bit clearer...
    I have 2 comboboxes and a text box...I have set the rowsource of the combobox1 to a1:a8 (these contain words, interestingly i had to use the index values as opposed to the actual words in the code for the code to work..i still dont know why?)...based on the selection of cmbx1 ..data is filled into cmbbox2.. i used the below code..

    Public Sub ComboBox1_Change()

    If ComboBox1.Value = 0 Then
    ComboBox2.RowSource = "Headings!B2:B30"
    ElseIf ComboBox1.Value = 1 Then
    ComboBox2.RowSource = "Headings!c2:c30"
    ElseIf ComboBox1.Value = 2 Then
    ComboBox2.RowSource = "Headings!d2:d30"
    ElseIf ComboBox1.Value = 3 Then
    ComboBox2.RowSource = "Headings!e2:e30"
    ElseIf ComboBox1.Value = 4 Then
    ComboBox2.RowSource = "Headings!f2:f30"
    ElseIf ComboBox1.Value = 5 Then
    ComboBox2.RowSource = "Headings!g2:g30"
    ElseIf ComboBox1.Value = 6 Then
    ComboBox2.RowSource = "Headings!h2:h30"
    ElseIf ComboBox1.Value = 7 Then
    ComboBox2.RowSource = "Headings!i2:i30"
    Else
    End If

    End Sub

    and then i want to vlookup the comboxbox2 selecttion againstt a range (TR) and then populate the result into the textbox2..

    i used the below code and it does not work.

    Public Sub TextBox1_Change()

    TextBox1.Value = WorksheetFunction.VLookup(ComboBox2.Value, Range("TR"), 2, False)

    End Sub
    Appreciate the help..thks

Posting Permissions

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