+ Reply to Thread
Results 1 to 29 of 29

VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Hey everyone,

    So my title is my issue, in a nutshell.

    I am looking up contact info that is attached to an ID number. This is so I can place the info on one worksheet, to another......but that's the simple part

    The ID number looks like this "AB-123456A1"

    I need the data on the contact list to remain like it looks above.....so I can't get rid of the first 3 characters, or last two characters........but I was wondering if it would be possible to use the VLOOKUP function......to lookup the characters in between?

    Please feel free to share any tips, or sample formulas based on any examples you can think of. Thanks guys! I'm really stumped!
    Last edited by bradallen; 09-18-2012 at 04:27 PM.

  2. #2
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Use MID to extract the search value.

    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


  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Hi bradallen and welcome to the forum.

    How about creating a helper column with a formula, something like this.
    =MID(A1,4,LEN(A1)-5)
    Use this helper column for the lookup.

    Does that help?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    I'll try these out tomorrow....is there any way to look it up without creating a helper column? Thanks everyone!

  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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Just use the formula provided as the search item.

    =VLOOKUP(MID(A1,4,LEN(A1)-5), search range, column, FALSE)

    Regards, TMS

  6. #6
    Registered User
    Join Date
    09-14-2012
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Try this:

    =MID(A1,FIND("-",A1,1)+1,LEN(A1)-FIND("-",A1,1)+1)

    your search value is in A1, putting it with vlookup the formula should show like this:
    =vlookup(MID(A1,FIND("-",A1,1)+1,LEN(A1)-FIND("-",A1,1)+1),"search range","column index",0)

    Hope this helps.

  7. #7
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Stupid Question....what does "-" mean?


    I've created an example spreadsheet. These formulas might work above but I don't understand yet what all of the symbols mean. I need the data in column 2 on sheet 2 to be looked up on sheet 1....but i need it to only look up the middle numbers (not the ab- or a1 because all of my data will have those characters. Thanks again!

    Example.xlsx

  8. #8
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    The "-" is searching for a hyphen (minus sign, whatever) in the cell A1.

    I suspect that it won't give you what you want as you have other data after the numeric part.

    Regards, TMS

  9. #9
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Assuming that you always lose three characters at the start and two characters at the end, MarvinP's formula will work.

    This amendment caters for blank cells:

    =IFERROR(MID(A2,4,LEN(A2)-5),"")

    This is a variation on rundie_d's formula:

    =IFERROR(MID(A4,FIND("-",A4,1)+1,LEN(A4)-FIND("-",A4,1)-2),"")

    This still assumes that you lose two characters at the end but you can have whatever you want before the hyphen.


    Regards, TMS

  10. #10
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Thanks for all the help everyone, I appreciate it. Again, is there anyway to do the formula that does not require a helper column?

  11. #11
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Have a look at the previous posts ... use the formula provided as the search item in the VLOOKUP.

  12. #12
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    It's working! The last thing I need to know is how to use IF.........because some of the codes do not have the A1 at the end but I still want vlookup to find them. Thanks!

  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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    =IF(RIGHT(A2,2)="A1",IFERROR(MID(A2,4,LEN(A2)-3),""),IFERROR(MID(A2,4,LEN(A2)-5),""))


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  14. #14
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Just about, how would that fit into the VLOOKUP formula?

  15. #15
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Feeling of deja vu ... it's the formula that you use as the search item (without the equals sign).


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  16. #16
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    I combined the two formulas together....the formula I used as the search item....with the IF formula.....and there's an error message....where does the IF formula go? And does it need a comma?

    Forgive me, I'm VERY new to Excel and greatly appreciate the help!

  17. #17
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Can anyone assist with this? I combined the two formulas together....the formula I used as the search item....with the IF formula.....and there's an error message....where does the IF formula go? And does it need a comma?

    Forgive me, I'm VERY new to Excel and greatly appreciate the help!

  18. #18
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    =VLOOKUP(IF(RIGHT(A2,2)="A1",IFERROR(MID(A2,4,LEN(A2)-5),""),IFERROR(MID(A2,4,LEN(A2)-3),"")), search_range, rcolumn, FALSE)


    where search_range is a named range for the lookup area and rColumn is a named range containing the column to return.

    =VLOOKUP(IF(RIGHT(A2,2)="A1",IFERROR(MID(A2,4,LEN(A2)-5),""),IFERROR(MID(A2,4,LEN(A2)-3),"")), $F:$G, 2, FALSE)


    Regards, TMS

  19. #19
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    TMShucks,

    I really appreciate all your help man, I'm sorry this is taking so long.

    The code above works in my sheet....but I need it to be able to look up data on another sheet that STILL contains the A1.

    I have a data dump with contact info that is not all formatted the same way....and the code above alleviates a lot of of issues BUT I still need the formula to be flexible and look up data that still has the A1 on it......

    Is there a way to have it look up the data....and retrieve it even if the A1 is still there? "True" isn't enough it seems, it selects the wrong data.

  20. #20
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    I am confused. You said:

    I need the data on the contact list to remain like it looks above.....so I can't get rid of the first 3 characters, or last two characters........but I was wondering if it would be possible to use the VLOOKUP function......to lookup the characters in between?
    So, you got a formula to do that. Then you wanted a VLOOKUP ... and you got a formula to do that.

    Then you said some codes don't have A1 so don't lose the last two characters ... and you were given a formula to do that.

    After that, you needed the latest formula to be inserted into the VLOOKUP ... and you got it.

    This is, as you understand, dragging on and becoming frustrating.

    Please post a sample workbook with all the variations that you expect to get, what you want them matched against, and what you expect to be returned. This doesn't require live data, just examples of what you are actually seeing, what, if anything they should match and the value that you want returning.

    If you make the sample workbook representative of what you are working with, you may well get an answer that addresses all the issues ... in one pass.

    Regards, TMS

  21. #21
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Example.xlsx

    Thanks for your response....here is the example file.

    I need the lookup formula to take the numbers off, because in most cases....that's the way our data is stored....but in some cases....it will need to look up the info with A1 will still on.

  22. #22
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    So, basically, you're saying: look up the code as it stands - if that's not there, take off the A1 if it's there and try again. And if that's not there, remove the State and try again.

    What is the frequency of each of the options? It doesn't make a lot of difference but it makes sense to look for the most frequent option first.

    Regards, TMS

  23. #23
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Yes!

    Just A1 and no state would be the most frequent, followed by no state and no A1, and then last would be both state and AI present.

  24. #24
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    With Excel 2007/2010 (from the extension), you could use this:

    =IFERROR(VLOOKUP(IFERROR(MID(A2,4,LEN(A2)-3),""),Sheet2!$B:$C, 2, FALSE),"")&IFERROR(VLOOKUP(IFERROR(MID(A2,4,LEN(A2)-5)*1,""),Sheet2!$B:$C, 2, FALSE),"")&IFERROR(VLOOKUP($A2,Sheet2!$B:$C,2,FALSE),"")

    Basically, it tries all the options and concatenates the results ... only one will be found (I think) and the others will be blank. This works for the three examples.

    If it's Excel 2003 from you profile, it will be the same premise, just longer ... quite a bit longer.


    Regards, TMS

  25. #25
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    It's working! BUT....I need to add trim....and then it's DONE! Do I just add that to the front?

  26. #26
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Trim what? The name returned? You need to remove leading and trailing spaces? Whatever ...

    =TRIM( ... the formula ...)

  27. #27
    Registered User
    Join Date
    09-13-2012
    Location
    aurora, il
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    Hard Data Example.xlsx


    TMS,

    You have been extremely helpful, ridiculously helpeful in fact. I understand things about Excel now that I had no clue about before. This is a new report and I basically understand everything we've discussed through your tips and reading about those functions.

    I've attached where I'm at now and I just don't get this last issue.

    Everything is working....but if data is pulled from a number with the A1 on it.......and the A1 is removed (to simulate a change in the data) it won't lookup the data based on the base code

    It should....because it does so in other cases where there is no IL- or A1....so what am i missing for those codes?

  28. #28
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    I don't know. You need to look at your data and see what should and should not match something.

    If you have, for example, IL-12345A1 with a description A, 12345A1 with a description B, and 12345 with a description C in the lookup table, with the latest formula, they are all going to match and you will get ABC, but not necessarily in that order. To avoid that, you'd probably need to make it a nested IF which would stop at the first match. I'm not sure what you would prefer ... do you need/want to know if there are multiple matches?

    I think you now have the building blocks and need to start experimenting for yourself.


    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  29. #29
    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
    44,447

    Re: VLOOKUP the middle characters, and ignore the first 3 characters and the last 2

    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)

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