+ Reply to Thread
Results 1 to 8 of 8

How to remove the rightmost N characters when the string length is variable

  1. #1
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    How to remove the rightmost N characters when the string length is variable

    Hello!

    I have a column of text values (strings) and would like to remove the rightmost 8 characters from each cell. The string length varies from cell to cell, however, so I don't believe I can use the LEN function. The rightmost 8 characters are in the form (xxxxxx).

    Thank you!

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

    Re: How to remove the rightmost N characters when the string length is variable

    If a formula is acceptable....
    Please Login or Register  to view this content.
    (I corrected the formula I originally posted....I saw "8" and typed "9")

    Is that something you can work with?
    Last edited by Ron Coderre; 12-17-2015 at 04:54 PM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,731

    Re: How to remove the rightmost N characters when the string length is variable

    Try this in B2, assuming the string is in A2:

    =LEFT(A2,LEN(A2)-8)

    Copy down as required.

    Hope this helps.

    Pete

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: How to remove the rightmost N characters when the string length is variable

    Replace A1 with your cell reference
    =IFERROR(LEFT(A1,LEN(A1)-8),A1)
    Last edited by JieJenn; 12-17-2015 at 04:55 PM.

  5. #5
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to remove the rightmost N characters when the string length is variable

    Thank you, everyone! For some reason, when I enter the formula, I'm seeing the formula itself--rather than the result of the formula. Any idea why that may be? I did go to File --> Options --> Formulas --> Workbook Calculation, and it is set to automatic.

  6. #6
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to remove the rightmost N characters when the string length is variable

    Also, both the source column and the destination column are formatted to Text (Select cells --> Format Cells--> Text).

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

    Re: How to remove the rightmost N characters when the string length is variable

    Either
    1) The cell containing the formula is formatted for TEXT.
    ...Change the number format to anything except text
    ...Edit the formula and press ENTER

    or
    2) The worksheet is set to display formulas, not their calculated values
    ...CTRL+~ <--the "~" is on the key above the TAB key
    or
    ...Formulas.Show_Formulas

    Does that help?

  8. #8
    Registered User
    Join Date
    03-22-2012
    Location
    M, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: How to remove the rightmost N characters when the string length is variable

    Thank you, Ron! Your advice resolved the problem, and the formula you provided worked as needed!

+ 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. Cell length formula to remove any characters over 31 in length
    By tehkayd in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-02-2015, 11:45 AM
  2. [SOLVED] VBA, remove all characters within a string, except numerical characters and full stops
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2015, 09:24 PM
  3. [SOLVED] Shorten string length if exceeds 31 characters (max sheet name length)
    By r2fro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2014, 05:57 AM
  4. Remove text of variable length from cell
    By dziw in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-27-2007, 01:06 PM
  5. Passing Variable length Space Characters to Variables
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-07-2006, 07:40 PM
  6. Replies: 1
    Last Post: 04-18-2005, 05:06 PM
  7. Replies: 1
    Last Post: 04-17-2005, 08: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