Closed Thread
Results 1 to 9 of 9

Problem with VLookup Function

  1. #1
    Registered User
    Join Date
    02-23-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Problem with VLookup Function

    Hi, I am new to vba and i needed help in this. My excel sheet consist of table names and variables and i am using a simple vlookup function to get the corresponding variable names for the particular table but the function is not working.In this the user selects the table names from the combobox and then the listbox should enter the corresponding variable names.
    my vlookup function for the Combobox is
    ListBox1.Value=Application.WorksheetFunction.VLookup(Me.ComboBox1.Value, Range("B:C"), 2, False)
    Attached Files Attached Files

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Problem with VLookup Function

    No code in your sample so hard to say but for starters your lookup range is in columns A:B, not B:C.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Problem with VLookup Function

    I notice you also posted this yesterday. Please read the forum rules. If you don't receive an answer bump the thread rather than posting a duplicate.

    Dom

  4. #4
    Registered User
    Join Date
    02-23-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Problem with VLookup Function

    Yeah i have changed that still it doesn't work. In my earlier post i wanted it in a different manner.

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Problem with VLookup Function

    Okay but we're going to find it very difficult to help with a sample workbook that doesn't actually demonstrate the problem though.

    Dom

  6. #6
    Registered User
    Join Date
    02-23-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Problem with VLookup Function

    The following code is not working for selecting the corresponding variables and adding to the listbox after the user selects the table name from the combobox.
    In my code cboTableName is the combo box
    AddList is the ListBox in which i have to add the variable names

    Public Sub cboTableName_Click()
    Dim i As Integer
    Dim lastrow As String
    Dim Value As String

    With Worksheets("Sheet1")

    lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row

    AddList.Clear
    For i = 2 To lastrow


    AddList.AddItem .Cells(i, "B").Value = Application.WorksheetFunction.VLookup(Me.cboTableName.Value, Range("A:B"), 2, False)
    Next i
    End With

    End Sub

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Problem with VLookup Function

    Please edit your post to include code tags as per the FORUM RULES.

    Dom

  8. #8
    Registered User
    Join Date
    02-23-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Problem with VLookup Function

    Hi, the following attachment is my workbook on which i am working on. The code which i have written is not giving the output which i want and it is printing 0. I know for a list of variables to be entered in the listbox i should use some other function other than VLookupor case statements. But i don't know which one i should use so that it gives me the variables according to the table name which i have mentioned in the drop down box. I hope you could help me with that.
    Attached Files Attached Files

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Problem with VLookup Function

    Are you going to edit your post?

Closed 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