+ Reply to Thread
Results 1 to 5 of 5

Extract from string and use result for vlookup - doesn't work?

Hybrid View

kingofcamden Extract from string and use... 06-15-2022, 05:30 PM
6StringJazzer Re: Extract from string and... 06-15-2022, 05:35 PM
TMS Re: Extract from string and... 06-15-2022, 05:36 PM
kingofcamden Re: Extract from string and... 06-15-2022, 05:55 PM
TMS Re: Extract from string and... 06-15-2022, 06:10 PM
  1. #1
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    215

    Question Extract from string and use result for vlookup - doesn't work?

    Hi all,

    So I have this string in cell C9 (WR.NEA.541.00.2022.06.15.I3) and want to extract the 541 value from it.
    Formula I used is this:

    Formula: copy to clipboard

    =TRIM(CLEAN(MID(SUBSTITUTE(C9,".",REPT(" ",100)),200,100)))


    I am now trying to use the output value (541) for a vlookup on another table so am combining the two formulae:
    Formula: copy to clipboard

    =VLOOKUP(TRIM(CLEAN(MID(SUBSTITUTE(C9,".",REPT(" ",100)),200,100))),Lookups!$B$6:$F$204,4,FALSE)


    (Note: Lookups!$B$6:$F$204 contains this number - triple-checked - and the 4th column contains the output value - also triple checked).

    This formula gives me a #N/A?!

    If I evaluate the formula, everything looks fine - it goes all the way to "VLOOKUP("541",Lookups!$B$6:$F$204,4,FALSE)", but then returns the #N/A. As if the value would not exist in range Lookups!$B$6:$F$204, when it 1000% does.

    Here are some things I've already tried:
    1. As REPT is rendering a Text format output, I thought Excel may not find a match as one cell is formatted as 'Text' and the other as 'General', but that's not it. Both values are formatted as 'General'
    2. I've also tried different formulae without REPT to extract the 541 value...same result:

    Formula: copy to clipboard

    =LEFT(TEXTJOIN("",TRUE,IFERROR(--MID(C9,ROW(INDIRECT("1:"&LEN(C9))),1),"")),LEN(TEXTJOIN("",TRUE,IFERROR(--MID(C9,ROW(INDIRECT("1:"&LEN(C9))),1),"")))-11)


    Formula: copy to clipboard

    =CLEAN(TRIM(LEFT(MID(C9,FIND("#",SUBSTITUTE(C9,".","#",2))+1,255),LEN(MID(C9,FIND("#",SUBSTITUTE(C9,".","#",2))+1,255))-22)))


    3. I've also tried INDEX/MATCH for the lookup...also did not work:

    Formula: copy to clipboard

    =INDEX(Lookups!$E$6:$E$204,MATCH(TRIM(CLEAN(MID(SUBSTITUTE(C9,".",REPT(" ",100)),200,100))), Lookups!$B$6:$B$204,0))


    Formula: copy to clipboard

    =INDEX(Lookups!$E$6:$E$204,MATCH(CLEAN(TRIM(LEFT(MID(C9,FIND("#",SUBSTITUTE(C9,".","#",2))+1,255),LEN(MID(C9,FIND("#",SUBSTITUTE(C9,".","#",2))+1,255))-22))), Lookups!$B$6:$B$204,0))


    #N/A errors all around...

    This is driving me nuts haha...Spent hours trying to fix this lookup, but no luck.

    Any thoughts?

    Appreciate the help!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner VA USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,568

    Re: Extract from string and use result for vlookup - doesn't work?

    Your first formula is giving you a string and the data you are searching is probably numbers. Try this revision to your second formula:

    Formula: copy to clipboard
    =VLOOKUP(VALUE(TRIM(CLEAN(MID(SUBSTITUTE(C9,".",REPT(" ",100)),200,100)))),Lookups!$B$6:$F$204,4,FALSE)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    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
    49,652

    Re: Extract from string and use result for vlookup - doesn't work?

    I suspect it is simply because you are using MID to extract some information. This will give a Text return, regardless of the content extracted. So, if the search table contains numeric data, it will not match ... "123" <> 123 as far as Excel is concerned.

    Try just adding zero at the end of your initial formula:
    Formula: copy to clipboard
    =TRIM(CLEAN(MID(SUBSTITUTE(C9,".",REPT(" ",100)),200,100)))+0



    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    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


  4. #4
    Forum Contributor
    Join Date
    08-25-2015
    Location
    London
    MS-Off Ver
    MS 365
    Posts
    215

    Re: Extract from string and use result for vlookup - doesn't work?

    OMG! For real?! Haha...the +0 did the job! Thanks TMS!

    6StringJazzer, good suggestion - had tried that too, but somehow did not work right.

    Happy I can finally close this chapter!

  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
    49,652

    Re: Extract from string and use result for vlookup - doesn't work?

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA doesn't work when string length more than 255 characters in the code lines
    By thup_98 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 06-30-2016, 04:40 AM
  2. [SOLVED] Add string as formula through code doesn't work with sumif
    By vizzkid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2016, 10:04 AM
  3. Editing the connection string doesn't seem to work
    By PMBTech in forum Excel General
    Replies: 0
    Last Post: 08-11-2014, 11:00 AM
  4. [SOLVED] Why my Vlookup doesn't work?
    By ypurcaro in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-06-2014, 08:25 PM
  5. [SOLVED] My code to find longest string in column doesn't work properly! Need Help!!
    By refree in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2013, 08:27 AM
  6. [SOLVED] VLOOKUP doesn't work for me
    By senorkevin in forum Excel General
    Replies: 10
    Last Post: 11-12-2012, 07:58 PM
  7. Replies: 5
    Last Post: 06-19-2006, 02:00 PM

Tags for this Thread

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