+ Reply to Thread
Results 1 to 9 of 9

Truncate cell ONLY if it contains string?

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    949

    Truncate cell ONLY if it contains string?

    Hi all!

    So Column W has emails, which occasional have long generated ones like so "guest-XXXXXXXXX"
    Other cells have normal emails.

    I want to truncate to say 10 characters (or whatever) only the cells with "guest-"

    Is this possible? Also must say this column is generated with a formula so that is important to, this is the existing formula in the cell which parses email from another column.

    Please Login or Register  to view this content.
    So basically, if the data in the cell from the formula above contains "guest-" I want to truncate to 10 characters.


    (Can you even truncate results into the same cell as the data? Or would it have to go in a new column?)
    Last edited by NewYears1978; 07-18-2018 at 10:55 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Truncate cell ONLY if it contains string?

    Good afternoon NewYears1978

    Perhaps something like the formula below, assuming your data is in column A and starts at row 1 :
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    And yes, it would have to go into a new column.
    If you want to upload a sample file, we may be able to determine if it's possible to roll both formulae together to do it in one operation.

    HTH

    DominicB

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Truncate cell ONLY if it contains string?

    I think I was able to do it awhile back but I can't recall how I did it =D

    My form is huge, has VLOOKUPS/INDEX and buncha stuff but I stripped it over only the two columns in question.
    I may just add a section column and hide the other.

    Edit:

    Also the formula didn't work all the time, I should have specified the number of digits after "guest-" varies...could be 10, 15, 20 or whatever..auto generated. So the formula didn't work all the time only part of the time.
    Attached Files Attached Files
    Last edited by NewYears1978; 07-18-2018 at 11:22 AM.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Truncate cell ONLY if it contains string?

    What do you want to end up with

    =Left(your_B2_formula,10) will truncate to 10 characters but I suspect that may not be what you expect.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Truncate cell ONLY if it contains string?

    Hi NewYears1978
    Quote Originally Posted by NewYears1978 View Post
    My form is huge, has VLOOKUPS/INDEX and buncha stuff but I stripped it over only the two columns in question.
    That's fine - we don't really need to see the rest of it.
    Something like this would suffice - not the most elegant formula you'll see, but it it seems to work OK :
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    HTH

    DominicB

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Truncate cell ONLY if it contains string?

    Try this
    Enter formula in B1 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Sheet: Sheet1
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2312
    Posts
    42,552

    Re: Truncate cell ONLY if it contains string?

    Intermediate between the simplicity of Alkey's and the complexity of dominics... my take:

    =IF(LEFT(MID(A1,SEARCH(":",A1)+1,255),5)="guest",LEFT(MID(A1,SEARCH(":",A1)+1,255),10),LEFT(MID(A1,SEARCH(":",A1)+1,255),SEARCH(">",MID(A1,SEARCH(":",A1)+1,255))-1))
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

  8. #8
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: Truncate cell ONLY if it contains string?

    Both worked great, and holy crap trying to read that is impossible.

    Thanks everyone!

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2312
    Posts
    42,552

    Re: Truncate cell ONLY if it contains string?

    You'rewelcome and 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)

Similar Threads

  1. [SOLVED] Need to truncate cell string to <len(30) but at " " (space)
    By sh_gaitonde3901 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 06-16-2016, 06:15 AM
  2. [SOLVED] truncate a string x characters after a delimiter
    By timmatthews in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-19-2013, 05:56 PM
  3. [SOLVED] Truncate a string to a certain value
    By fenfool in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-19-2013, 10:29 AM
  4. Truncate a string
    By Xx7 in forum Excel General
    Replies: 5
    Last Post: 04-04-2011, 06:07 PM
  5. Replies: 3
    Last Post: 09-09-2010, 10:41 AM
  6. Truncate String
    By ajocius in forum Excel General
    Replies: 2
    Last Post: 05-06-2009, 10:37 AM
  7. How do you truncate a text string?
    By dailygluttony in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-28-2006, 03:10 PM

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