+ Reply to Thread
Results 1 to 6 of 6

Vlookup in form.

Hybrid View

  1. #1
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Vlookup in form.

    hi,,

    i had created a user form where i want to show the values in the listbox based on values from combobox.i had used the vlookupfunction to get so.I m getting an error.Is my syntax for the function incorrect..kindly tell me...
    Attached Files Attached Files
    Last edited by excelkeechak; 02-17-2012 at 09:54 PM.
    THANKS
    ExcelKeechak

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Vlookup in form.

    I can find no formulas or anything in your workbook, just 3 plain columns of info. Did you upload the correct file?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Vlookup in form.

    Your VLOOKUP fomula wouldn't work even in a sheet, the Lookup value should be in the first column of the lookup table
    Rename tab to be =Sheet1!$B$2:$B$6, note how the range is referred to in the code.
    Private Sub ComboBox1_Change()
    ListBox1.AddItem Worksheetfunction.VLookup(ComboBox1.Value, Range("tab"), 2, 0)
    End Sub
    A better way would be to use
    Private Sub ComboBox1_Change()
    ListBox1.AddItem Cells(ComboBox1.ListIndex + 2, 3).Value
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Re: Vlookup in form.

    Thanks mr.Roy..the second code works.but the list box is not cleared when a new selection is made in the combobox....?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Vlookup in form.

    It's a simple fix & you should check out control properties in the Object Browser if you want to learn VBA

    Private Sub ComboBox1_Change()
    Listbox1.Clear
    Listbox1.AddItem Cells(ComboBox1.ListIndex + 2, 3).Value
    End Sub

  6. #6
    Forum Contributor excelkeechak's Avatar
    Join Date
    07-21-2008
    Location
    India.
    MS-Off Ver
    2013 /2016
    Posts
    363

    Re: Vlookup in form.

    thanks roy....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1