+ Reply to Thread
Results 1 to 8 of 8

Mid function breakdown

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Mid function breakdown

    Can someone please breakdown in layman's terms the num_chars part of this function for my formula: =MID(C40,(SEARCH("""",C40,1)+1),(SEARCH("""",C40,((SEARCH("""",C40,1))+1)))-(SEARCH("""",C40,1))-1)

    When I separate SEARCH("""",B48,SEARCH("""",B48,1)+1)-(SEARCH("""",B48,1)-1) into its own cell for portfolio="qen002524" I get 11 but I can't explain it. The whole function is "simply" returning whatever is in b/t the quotes but the last part is confusing me when I try to dissect it.

    Does the num_chars part say I am starting at the second quote less anything before the character after the first quote? The parenthesis make it really confusing and could be place in different spots but I am having trouble. Let me know if this makes sense.

    Thanks

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

    Re: Mid function breakdown

    For the num_chars you want to find the char_num-1 of the last " and subtract the char_num+1 of the 1st ".

    If the string to be extracted is always at the end of the larger string then try this version:

    =SUBSTITUTE(MID(C40,FIND("""",C40)+1,50),"""","")
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Mid function breakdown

    That formula uses a round-about way of calculating the start and length arguments of the MID function.

    Here are some other options:
    If the quoted value can be anywhere in cell C40
    =MID(LEFT(C40,FIND("|",SUBSTITUTE(C40,"""","|",2))-1),FIND("""",C40)+1,255)

    If the quoted value is ALWAYS at the end of the string in cell C40
    =MID(LEFT(C40,LEN(C40)-1),FIND("""",C40)+1,LEN(C40))

    Are either of those easier to decipher?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Registered User
    Join Date
    06-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Mid function breakdown

    Ron, what does the pipe mean or signify? Not sure where that falls into place

    Also, is the num_chars arbitrary b/c both of you have quite large numbers?
    Last edited by egut; 06-18-2013 at 04:20 PM.

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

    Re: Mid function breakdown

    Quote Originally Posted by egut View Post
    is the num_chars arbitrary b/c both of you have quite large numbers?
    Basically, yes.

    num_chars needs to be a big enough number that it returns all the chars after the 1st quote.

    I assumed that your example string:

    portfolio="qen002524"

    Was typical of your data so num_chars of 50 would suffice. You can always use a smaller number if you want since no one knows your data like you do!

  6. #6
    Registered User
    Join Date
    06-17-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Mid function breakdown

    correct, almost all of the data is similar in that it will look like XXXXXXX="*******", but i was just wondering. Thanks

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

    Re: Mid function breakdown

    Quote Originally Posted by egut View Post
    Thanks
    You're welcome!

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Mid function breakdown

    Quote Originally Posted by egut View Post
    Ron, what does the pipe mean or signify? Not sure where that falls into place
    In the formula I posted: =MID(LEFT(C40,FIND("|",SUBSTITUTE(C40,"""","|",2))-1),FIND("""",C40)+1,255)
    the SUBSTITUTE function replaces the second quote (") with a pipe character (|).
    It breaks down this way:
    C40: portfolio="some value"
    =MID(LEFT(C40,FIND("|",SUBSTITUTE(C40,"""","|",2))-1),FIND("""",C40)+1,255)
    =MID(LEFT(C40,FIND("|","portfolio=""some value|")-1),FIND("""",C40)+1,255)
    =MID(LEFT(C40,21),FIND("""",C40)+1,255)
    =MID("portfolio=""some value",FIND("""",C40)+1,255)
    =MID("portfolio=""some value",12,255)
    ="some value"

+ 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