+ Reply to Thread
Results 1 to 12 of 12

Complex Left, Right, Mid Scenario

  1. #1
    Registered User
    Join Date
    05-19-2016
    Location
    West Orange, NJ
    MS-Off Ver
    2007
    Posts
    3

    Complex Left, Right, Mid Scenario

    Attachment 461689

    As you can see in the image above, I have a category column on one sheet. This column contains more than 100 distinct values. On another page I have the file name column with several thousand values. Essentially the category is contained within each file name and I want a column that contains the corresponding category that is found within the name. I tried a mid and find function. This would technically work except that there are 100 categories so you would need 100 nested statements which is neither feasible or possible with the 64 statement limit for excel. In addition, left and right functions would be difficult since the character count before and after the category in the name differs frequently. Is there any way to essentially the category within the cell? What would be the best way to go about solving this?
    Attached Files Attached Files
    Last edited by blaise.barra; 05-19-2016 at 02:54 PM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Complex Left, Right, Mid Scenario

    Please post a file as (a) many of us cannot view PNG images and (b) we need data test out any solutions.

    To upload a file click "Go Advanced" then scroll down to "Manage Attachments".

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Complex Left, Right, Mid Scenario

    Try this...

    Data Range
    A
    B
    C
    D
    1
    Category
    ------
    File Name
    Category
    2
    Dog
    Test_123_Dog_1234.txt
    Dog
    3
    Cat
    Test_125_Bird_1234.txt
    Bird
    4
    Bird
    Test_132_Bird_1234.txt
    Bird
    5
    Test_125234532_Bird_123212234.txt
    Bird
    6
    Test_121123425_Cat_1232222224.txt
    Cat


    This formula entered in D2 and copied down:

    =IFERROR(LOOKUP(1000,SEARCH(A$2:A$4,C2),A$2:A$4),"")
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Complex Left, Right, Mid Scenario

    Thank you for the file: all are file names of the same format as those in your sample i.e category 3rd "element" (xxx_yyy_CATEGORY___ZZZZ?

  5. #5
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Complex Left, Right, Mid Scenario

    Hi
    I use a second sheet to create a table of categories (Categories!A2:A13)
    After that use the formula in E2 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    See the file Vlookup Question 2.xlsx

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Complex Left, Right, Mid Scenario

    Another way if the category is always between the 2nd and 3rd underscores...

    =TRIM(MID(SUBSTITUTE(C2,"_",REPT(" ",100)),200,100))

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Complex Left, Right, Mid Scenario

    @Tony, Yet again for my education - how does formula return the text? SEARCH finds where a word starts in the string: how does the LOOKUP work?

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Complex Left, Right, Mid Scenario

    Test_123_Dog_1234.txt

    =IFERROR(LOOKUP(1000,SEARCH(A$2:A$4,C2),A$2:A$4),"")

    If the search string is not found SEARCH returns the #VALUE! error...

    SEARCH("Dog",C2) = 10
    SEARCH("Cat",C2) = #VALUE!
    SEARCH("Bird",C2) = #VALUE!

    LOOKUP returns the value from A2:A4 that corresponds to the number value in the SEARCH array:

    LOOKUP(1000,{10;#VALUE!;#VALUE!},A2:A4)

    =A2

    So...

    =IFERROR(LOOKUP(1000,SEARCH(A$2:A$4,C2),A$2:A$4),"")

    =Dog

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Complex Left, Right, Mid Scenario

    @Tony, thank you again.

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Complex Left, Right, Mid Scenario

    You're welcome!

  11. #11
    Registered User
    Join Date
    05-19-2016
    Location
    West Orange, NJ
    MS-Off Ver
    2007
    Posts
    3

    Re: Complex Left, Right, Mid Scenario

    @Tony Thanks for the help!

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Complex Left, Right, Mid Scenario

    You're welcome!

+ 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. Complex 'IF' scenario
    By henrylwh in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-14-2015, 10:05 PM
  2. [SOLVED] Complex VLOOKUP with LEFT RIGHT function
    By janagan in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-12-2014, 01:32 AM
  3. Replies: 4
    Last Post: 02-03-2014, 12:47 AM
  4. LEFT RIGHT MID complex problem
    By ch9sab in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-17-2014, 05:57 AM
  5. Mail Merge : All-in-1 Page with Complex Scenario
    By donkeybusiness in forum Word Formatting & General
    Replies: 4
    Last Post: 01-30-2013, 03:06 AM
  6. Scenario Manager displays same result for every scenario
    By terihoff in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 11-10-2012, 07:14 PM
  7. Replies: 0
    Last Post: 08-16-2012, 01:32 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