+ Reply to Thread
Results 1 to 11 of 11

VLOOKUP w/ LEFT Function

  1. #1
    Registered User
    Join Date
    12-07-2009
    Location
    UTAH
    MS-Off Ver
    Excel 2007
    Posts
    14

    VLOOKUP w/ LEFT Function

    Function sequence giving me "N/A": =VLOOKUP(LEFT(C6,5),H:I,2,FALSE)

    Basically, I have numbers that each start with a unique sequence. The first 5 numbers of that sequence represent a certain cell carrier.

    What I want to do is have the function look up the first 5 characters of a cell and depending on the 5 characters, I want it to return a certain value.

    My idea with the vlookup was to have the lookup value be the first 5 digits and then in my table, it would take only those 5 digits and return a value I have specified in the second column.

    Any help on my particular function or if you have another function, I would greatly appreciate it.

    Thanks,
    Alan

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Post Re: VLOOKUP w/ LEFT Function

    Does the value in the table (left most value) equal only the five characters you are searching or are they the entire number? They must match.

  3. #3
    Registered User
    Join Date
    12-07-2009
    Location
    UTAH
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VLOOKUP w/ LEFT Function

    Quote Originally Posted by rocky1 View Post
    Does the value in the table (left most value) equal only the five characters you are searching or are they the entire number? They must match.
    Yep and they are also ascending.

  4. #4
    Registered User
    Join Date
    12-07-2009
    Location
    UTAH
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VLOOKUP w/ LEFT Function

    I should add that I would simply use the IF function but that only deals with 2 scenarios. In my case, I have 3 scenarios.

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,318

    Post Re: VLOOKUP w/ LEFT Function

    Maybe you can attach a small sample of your workbook.

    I'm leaving in a few minutes, but I'm sure by the time I get back somebody else will have taken a look or I will get it.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: VLOOKUP w/ LEFT Function

    Can you post a little data sample? What does C6 look like? numbers with leading zeros stored as text? numbers formatted with leading zeros? you may need to jump through several hoops here. Try out what

    =left(c6,5) yields on its own. What does excel do with it?

    you may need

    =text(left(c6,5),"0000#")

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: VLOOKUP w/ LEFT Function

    I should add that I would simply use the IF function but that only deals with 2 scenarios. In my case, I have 3 scenarios.
    Ehmm, no problem. That can be constructed as well. Just explain the logic and we'll find a way ...

  8. #8
    Registered User
    Join Date
    12-07-2009
    Location
    UTAH
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VLOOKUP w/ LEFT Function

    Quote Originally Posted by rocky1 View Post
    Maybe you can attach a small sample of your workbook.

    I'm leaving in a few minutes, but I'm sure by the time I get back somebody else will have taken a look or I will get it.
    Thanks for the help...

    I've attached a simple example document of what I am dealing with.

    As you'll see, the first 5 numbers indicate which cell carrier the whole number belongs to.
    Attached Files Attached Files

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: VLOOKUP w/ LEFT Function

    The result of your LEFT() is a text value. Your lookup table has numbers. So you have to make sure both are of the same data type before you do the lookup. The easiest would be

    =VLOOKUP(--LEFT(A1,5),$H$1:$I$3,2,FALSE)

    or

    =VLOOKUP(LEFT(A1,5)*1,$H$1:$I$3,2,FALSE)

    Oh, I changed the lookup table reference. No need to reference the whole column!!!

    hth

  10. #10
    Registered User
    Join Date
    12-07-2009
    Location
    UTAH
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VLOOKUP w/ LEFT Function

    Quote Originally Posted by teylyn View Post
    The result of your LEFT() is a text value. Your lookup table has numbers. So you have to make sure both are of the same data type before you do the lookup. The easiest would be

    =VLOOKUP(--LEFT(A1,5),$H$1:$I$3,2,FALSE)

    or

    =VLOOKUP(LEFT(A1,5)*1,$H$1:$I$3,2,FALSE)

    Oh, I changed the lookup table reference. No need to reference the whole column!!!

    hth
    Awesome stuff! So, that "*1" you added seems to have fixed it. What exactly is it doing if you don't mind me asking?

    Thanks,
    Alan

  11. #11
    Registered User
    Join Date
    12-07-2009
    Location
    UTAH
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VLOOKUP w/ LEFT Function

    Quote Originally Posted by AlanH View Post
    Awesome stuff! So, that "*1" you added seems to have fixed it. What exactly is it doing if you don't mind me asking?

    Thanks,
    Alan
    I figured it out. I guess that just makes it turn itself into a number by completing an equation.

    Cool. Thanks again for your help.

+ 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