+ Reply to Thread
Results 1 to 16 of 16

remove everything but the last three characters at the end of the cell?

  1. #1
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    remove everything but the last three characters at the end of the cell?

    Hi Guys,

    Can someone help me write conditional code that will remove everything but the last 3 characters in a cell of column E if there is data in the cell of column F. If there is no data in the cell of column E then clear all data in the cell of column F.

    ie: if cell 4F has data then remove everything but last 3 characters in 4E cell if no data in cell 4F then clear all data 4E

    Thanks in advance, let me know if you need more clarification.

    Last edited by Rabbitstew; 06-13-2012 at 04:55 PM. Reason: Clarity

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

    Re: remove everything but the last three characters at the end of the cell?

    =IF(F2<>"",LEFT(E2,LEN(E2)-3),"")

    replace the last "" with what you want if F2 is blank.
    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
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    Thanks for your help but it's suppose to remove everything BUT the last 3 characters, in fact, I'd like to add maybe leave last 3 numeric values and ignore letters & symbols.

    ie:
    BEFORE RUNNING CODE:
    Search with Rafe Mair, The (2): Ep 8
    RESULT AFTER RUNNING CODE:

    8
    Last edited by Rabbitstew; 06-14-2012 at 12:13 PM.

  4. #4
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    Can anyone help me out?

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

    Re: remove everything but the last three characters at the end of the cell?

    Sorry, your thread got lost in the shuffle since yesterday...

    Try:

    =RIGHT(RIGHT(E2,3),3-MIN(FIND(0,SUBSTITUTE(RIGHT(E2,3),{1,2,3,4,5,6,7,8,9},0)&0))+1)+0

  6. #6
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    NBVC: no problem, thanks for your reply and the code works like a charm! However, upon running the code I realized the original condition will need to be replaced due to information I had not anticipated.

    Condition needed: If the cell of column E has "@", "/" and or no numbers at all, then insert a single space in the cell of column F.

    Thanks again in advance!

    Quote Originally Posted by NBVC View Post
    Sorry, your thread got lost in the shuffle since yesterday...

    Try:

    =RIGHT(RIGHT(E2,3),3-MIN(FIND(0,SUBSTITUTE(RIGHT(E2,3),{1,2,3,4,5,6,7,8,9},0)&0))+1)+0

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

    Re: remove everything but the last three characters at the end of the cell?

    What do you mean by insert a single space in cell of column F? Do you just want the cell to be blank, if there are any of those chars found?

  8. #8
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    Yes that's correct because I'm getting "#VALUE" errors in the cells that meet the conditions mentioned in previous post. I need these cells to be blank, that's why I said insert space unless there is a better solution-I'm all for it! Thanks again!

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

    Re: remove everything but the last three characters at the end of the cell?

    try:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    hrmmm.... I seem to be getting a "#NAME?" error now.

  11. #11
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: remove everything but the last three characters at the end of the cell?

    IFERROR is not a valid function in Excel 2003. Perhaps this update formula will work (using IF(ISERROR(...))):
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    BINGO! you are THE MAN! Thanks so much, works flawlessly.
    Last edited by Rabbitstew; 06-20-2012 at 09:17 AM.

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

    Re: remove everything but the last three characters at the end of the cell?

    Sorry for the misguidance... I need to remember that not everyone has moved up to 2007 or 2010...

  14. #14
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    One more question, I'm trying to create a macro to copy and paste this code for the entire column without any luck, would you happen to know how to do this?

  15. #15
    Registered User
    Join Date
    06-20-2012
    Location
    PA
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: remove everything but the last three characters at the end of the cell?

    Hi, Rabbitstew
    if your formula located in cell B2, and you want to copy formula in cells B3:B100, than the code will be:
    Range("B2").Select
    Selection.AutoFill Destination:=Range("B2:B100")

  16. #16
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    Thanks for your response but how do I paste the following code into the script?

    This is what I have so far:

    ' Macro2 Macro
    ' Macro recorded 6/20/2012 by Paul Wong
    '

    '
    Columns("F:F").Select
    Selection.Insert Shift:=xlToRight
    Range("F2").Select
    ActiveSheet.Paste
    ActiveSheet.Paste
    Range("F2").Select
    Selection.AutoFill Destination:=Range("F2:F349"), Type:=xlFillDefault
    Range("F2:F349").Select
    ActiveWindow.SmallScroll Down:=-90
    ActiveWindow.LargeScroll Down:=-1
    Range("F215").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F183").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F151").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F119").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F87").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F55").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F23").Select
    ActiveWindow.LargeScroll Down:=-1
    Range("F23").Select
    End Sub
    and where it says "ActiveSheet.Paste" I want to paste the following code in there:

    =IF(OR(ISNUMBER(SEARCH({"@","/"},E2))),"",IF(ISERROR(RIGHT(RIGHT(E2,3),3-MIN(FIND(0,SUBSTITUTE(RIGHT(E2,3),{1,2,3,4,5,6,7,8,9},0)&0))+1)+0),"",RIGHT(RIGHT(E2,3),3-MIN(FIND(0,SUBSTITUTE(RIGHT(E2,3),{1,2,3,4,5,6,7,8,9},0)&0))+1)+0))
    I tried inserting it as text but I get a script error. Any help would be appreciated.

  17. #17
    Registered User
    Join Date
    01-22-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    75

    Re: remove everything but the last three characters at the end of the cell?

    ThePower,

    But how do I create a macro that will automatically paste the formula into B2, have it be recognized as a formula and then paste itself down the entire column?

+ 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