+ Reply to Thread
Results 1 to 3 of 3

vlookUp not working

  1. #1
    Registered User
    Join Date
    12-23-2007
    Posts
    47

    vlookUp not working

    I have tried using vLookUp to look up a name and return a phone number. It works sometime, but not 100% of the time.

    Name Phone
    John Smith 519-555-6666
    James Smart 519-555-8888
    Jason Black 519-555-8983

    Since it did not work I tried writing my own look up but that also has caused problems. Comment on either one would be helpful

    Function Phone(Name As String)
    Dim Column As Integer

    Column = 10
    x = 2
    Do
    If Name = Worksheets("Settings").Cells(x, Column).Value Then
    Exit Do
    End If
    x = x + 1
    Loop Until Cells(x, Column) = ""
    Phone = Worksheets("Settings").Cells(x, Column + 1)

    End Function

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please read the forum rules and edit your post to add code tags.

  3. #3
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    199
    Do you have an example of the VLOOKUP formula that you were using. I put your data into a sample sheet and it worked fine with the data below in the range A1:B4

    Name Phone
    John Smith 519-555-6666
    James Smart 519-555-8888
    Jason Black 519-555-8983

    Then, in A7 I put in a data validation list of the names in A2:A4 and the following formula in C7.

    =VLOOKUP(A7,$A$1:$B$4,2,FALSE)

    If you didn't put in the "FALSE" statement as your "[Range Lookup]" it is very likely that you had some errors return as you have to have the range sorted in ascending order with the VLOOKUP Formula. See these notes from the Excel help file regarding this formula.

    Syntax
    VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)

    Lookup_value The value to search in the first column of the table array (array: Used to build single formulas that produce multiple results or that operate on a group of arguments that are arranged in rows and columns. An array range shares a common formula; an array constant is a group of constants used as an argument.). Lookup_value can be a value or a reference. If lookup_value is smaller than the smallest value in the first column of table_array, VLOOKUP returns the #N/A error value.

    Table_array Two or more columns of data. Use a reference to a range or a range name. The values in the first column of table_array are the values searched by lookup_value. These values can be text, numbers, or logical values. Uppercase and lowercase text are equivalent.

    Col_index_num The column number in table_array from which the matching value must be returned. A col_index_num of 1 returns the value in the first column in table_array; a col_index_num of 2 returns the value in the second column in table_array, and so on. If col_index_num is:

    Less than 1, VLOOKUP returns the #VALUE! error value.
    Greater than the number of columns in table_array, VLOOKUP returns the #REF! error value.
    Range_lookup A logical value that specifies whether you want VLOOKUP to find an exact match or an approximate match:

    If TRUE or omitted, an exact or approximate match is returned. If an exact match is not found, the next largest value that is less than lookup_value is returned.
    The values in the first column of table_array must be placed in ascending sort order; otherwise, VLOOKUP may not give the correct value. You can put the values in ascending order by choosing the Sort command from the Data menu and selecting Ascending. For more information, see Default sort orders.

    If FALSE, VLOOKUP will only find an exact match. In this case, the values in the first column of table_array do not need to be sorted. If there are two or more values in the first column of table_array that match the lookup_value, the first value found is used. If an exact match is not found, the error value #N/A is returned.
    Hope that helps.

+ 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