+ Reply to Thread
Results 1 to 10 of 10

Shortening text with MID

Hybrid View

  1. #1
    Registered User
    Join Date
    10-09-2006
    Posts
    36

    Shortening text with MID

    I'm using this function to make a short description of a product from a long description.

    =MID(K2,1,200)&"…"

    So it's taking the first 200 characters of cell K2 and adding a ... to it.

    Whats happening is it is splitting words and ending at character 200 instead of the end of the closest word to character 200.

    Is there a way to alter this formula to break at the end of a word close to character 200?

    Or is there a better way to do this?

    Thanks!

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Try:

    =LEFT(K2,FIND("^^",SUBSTITUTE(K2," ","^^",200-LEN(SUBSTITUTE(LEFT(K2,200)," ",""))+1))-1)
    This should take you to the closest space after character 200

    If you want to go to the closest space before character 200, take away the +1 in the formula.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    10-09-2006
    Posts
    36
    Right on the money!!!!

    Thanks!

  4. #4
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    A shorter way to go to the first space after 200 is =LEFT(K2,FIND(" ",K2,200)-1)

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by darkyam
    A shorter way to go to the first space after 200 is =LEFT(K2,FIND(" ",K2,200)-1)
    I like to complicate things...

  6. #6
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    I get enough from posts from DLL reminding me that I have the same habit. It feels good to be on this end of it for a change. Cute baby.

  7. #7
    Registered User
    Join Date
    10-09-2006
    Posts
    36
    Quote Originally Posted by darkyam
    A shorter way to go to the first space after 200 is =LEFT(K2,FIND(" ",K2,200)-1)
    The problem with this one is that it leaves the last space in the result so you have character 200 then a space.

    Hmmm, in the email of this it was missing the -1. I think someone sneakily fixed it!

    This should work.
    Last edited by theblade24; 04-02-2008 at 11:45 AM.

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by theblade24
    The problem with this one is that it leaves the last space in the result so you have character 200 then a space.
    For me it yields the same result as my formula...

    but you can always use TRIM to get rid of trailing spaces

    =Trim(Left(K2,Find(" ",K2,200)-1))

    Note: this will get rid of all extra spaces in the string...

+ 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