+ Reply to Thread
Results 1 to 13 of 13

Lookup on first five char

  1. #1
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Lookup on first five char

    Does anyone know why this formula is not working when it gets to line 75? I'm trying to return a value on based on the first five characters.

    Thanks!
    Attached Files Attached Files
    Last edited by day92; 01-03-2012 at 08:18 PM.

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

    Re: Lookup on first five char

    If I understand this right, why not use a Vlookup...

    Try this on C75...

    =VLOOKUP(LEFT(A75,5)+0,wru_cpt!$A$2:$C$7910,3,0)

    ...and since you are using 2007 you could use the IFERROR when there is not a match
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Re: Lookup on first five char

    Yeah that works.

    Whats the point of the +0 after the left formula? I dont get that part.

  4. #4
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,082

    Re: Lookup on first five char

    You're LEFTing the array but you're not LEFTing the value on Shindel
    This cures it

    =SUMPRODUCT(--(LEFT(wru_cpt!$A$3:$A$7910,5)=LEFT(A4,5)&""),wru_cpt!$C$3:$C$7910)

    and copy column C

    Values on Shindel from row 75 are longer than 5 characters
    so you're comparing the array with Shindel's original values

    Re jeffreybrowns answer: Adding +0 turns the resut into a number rather than a string
    Last edited by Special-K; 01-03-2012 at 07:16 PM.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,553

    Re: Lookup on first five char

    Jeff's formula will give #N/A for a "miss".

    Modifying your formula:

    Row 3: =SUMPRODUCT(--(LEFT(wru_cpt!$A$3:$A$7910,5)=LEFT(A4,5)&""),wru_cpt!$C$3:$C$7910)

    and copy down.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: Lookup on first five char

    This should help you bit VBA normal stuff

    in cell A1 just exactly this

    jackintheuk

    Now run this code and your get jacki ONLY - edit to suite, codes pretty basic so hope helps or post back for more help

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Re: Lookup on first five char

    Thanks everyone for your assistance.

    Actually I modified Jeff's formula to account for the misses. TMS your formula works but it is picking up extra values for a few of the codes. Take a look at line 47 & 61.
    Attached Files Attached Files

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

    Re: Lookup on first five char

    @Day92,

    Can you confirm what the result for 99213 and 99253 should be?

    @TMS,
    That is why I also suggested the use of IFERROR. Wouldn't this suffice? It also seems like Vlookup would be a more appropriate choice over Sumproduct. Am I wrong in my thinking?

  9. #9
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Re: Lookup on first five char

    99213 should be 1.01
    99253 should be 2.36

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

    Re: Lookup on first five char

    Okay, thank you for the confirmation. So the Vlookup should be working for you then, right?

    The +0 is just a way to take a number which could be masquerading as text and converts it to a number.

    I also did a quick time test between the Sumproduct and Vlookup. The results .969 and .04 respectively.

    http://msdn.microsoft.com/en-us/library/aa730921.aspx

  11. #11
    Forum Contributor day92's Avatar
    Join Date
    04-20-2010
    Location
    Los Angeles
    MS-Off Ver
    Excel 360
    Posts
    600

    Re: Lookup on first five char

    Jeff - yes the vlookup worked. I learned something new today. Thanks again!

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

    Re: Lookup on first five char

    Glad you found the help you needed

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,553

    Re: Lookup on first five char

    @Jeff: sorry, missed that comment. I agree that VLOOKUP is the better option; I was just thinking "inside the box" and making the original formula work

    Regards, TMS

+ 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