+ Reply to Thread
Results 1 to 8 of 8

MID Function w/ Variable Field Length and Spaces

  1. #1
    Registered User
    Join Date
    02-14-2011
    Location
    MidWest
    MS-Off Ver
    Excel 2007
    Posts
    9

    MID Function w/ Variable Field Length and Spaces

    Good Day,

    I am trying to break the data in column "A" into four different components as shown in columns B,C,D. and E.

    1) I can extract the data for column "B" by using the formula: =LEFT(A2,FIND(" ",A2)-1)

    After that, I am pretty much stuck because the text varies in length between the blank spaces? Any suggestions?

    Thanks
    Attached Images Attached Images

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: MID Function w/ Variable Field Length and Spaces

    Perhaps:

    Please Login or Register  to view this content.
    if content is always numeric and you want to return numbers coerce accordingly - ie add +0 to the above
    (for numbers - where coercing and where no. items may vary per string you can wrap the above+0 in an IFERROR to return a Null where no number exists)
    Last edited by DonkeyOte; 02-14-2011 at 09:41 AM. Reason: added TRIM in light of posts #6/7

  3. #3
    Registered User
    Join Date
    02-14-2011
    Location
    MidWest
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: MID Function w/ Variable Field Length and Spaces

    Thanks for the quick response. The solution does indeed work for extracting the information for Column "B", but how would I go about extracting the values for Columns C, D, and E? And sometimes the data can be alphanumeric. Thanks.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: MID Function w/ Variable Field Length and Spaces

    As inferred by "apply to results matrix" the formula dragged across will return each term in succession until such time as no more terms may be found.

  5. #5
    Registered User
    Join Date
    02-14-2011
    Location
    MidWest
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: MID Function w/ Variable Field Length and Spaces

    Brilliant! Thank you so much.

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

    Re: MID Function w/ Variable Field Length and Spaces

    Hi crew696
    Here is another formula that DO taught me a few months ago.
    Please Login or Register  to view this content.
    Put the above formula in B2 and pull formula to the right and then down to get you answers.
    Find the attached..
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: MID Function w/ Variable Field Length and Spaces

    Yes, I forgot to add the TRIM to my prior suggestion - now edited - thanks
    I had originally coerced to number then in hindsight removed the coercion and forgot to add back the TRIM

    @MarvinP, IMO better to use COLUMNS construct than COLUMN()+adjustment ... should you insert a column between say A & B the latter approach will cease to function correctly.

    edit:
    Further to above point... COLUMNS returns a scalar 1 whereas COLUMN actually returns an array {1}
    In this instance this won't affect result but given we want a scalar here it makes sense (IMO) to use the appropriate function.
    Last edited by DonkeyOte; 02-14-2011 at 09:49 AM. Reason: I wish I could type

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

    Re: MID Function w/ Variable Field Length and Spaces

    After some testing (my signature line) it looks like inserting Column A or B is the only time a problem occures.

    I accept you opinion as valid. BUT - it was hard enough to come up with the "blow up the spaces" formula on my own. I couldn't find the first time you showed this to me. It was like magic. It took me about 5 tries at the formula to understand. I really think the first time you showed this (trick?) to me the formula was shorter.

    Thanks for being my/our teacher.

+ 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