+ Reply to Thread
Results 1 to 7 of 7

Removing Spaces from Beginning & End of a Cell

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 / 2007
    Posts
    10

    Removing Spaces from Beginning & End of a Cell

    At the moment, I have Cells in a workbook that have "_" in the beginning, or end, or both. I have two commands to remove the _ in one or the other, but I cannot get it to do both in one sitting. I really just need to remove "_" from the beginning and end of the cell. If what i'm doing will not work, please let me know if there is a way.

    A1: _Direct
    B1: Direct_
    C1: _Direct_

    The Two Commands i have are below.
    =IF(RIGHT(A2)="_",RIGHT(A2,LEN(A2)-1),"")
    =IF(LEFT(A2)="_",LEFT(A2,LEN(A2)-1),"")

    These work for A1 & B1, however C1 will only do one or the other. I tried adding both If Statements together, however what i got was "Direct__Direct".. which did not really do what i wanted.

    The word "Direct" will change to show an Agency we have in our list.
    Example:
    "_Jon_Doe_Agency"
    "Doe_Agency_"
    "_John_INS_"

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Removing Spaces from Beginning & End of a Cell

    Hi and welcome to the forum

    Try this instead...
    =SUBSTITUTE(A2,"_","")
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Removing Spaces from Beginning & End of a Cell

    are there any in the middle?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    11-02-2012
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 / 2007
    Posts
    10

    Re: Removing Spaces from Beginning & End of a Cell

    Yes, there are.. I didnt notice it was taking all of them out.

    I added a xls showing that it is 'started' and 'finished' should be.

    Database Error.xls
    Last edited by aelingil; 10-01-2013 at 04:19 PM. Reason: (Updating w/ excel file)

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Removing Spaces from Beginning & End of a Cell

    =substitute(substitute("__"&a2&"__","___",""),"__","")

  6. #6
    Registered User
    Join Date
    11-02-2012
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003 / 2007
    Posts
    10

    Re: Removing Spaces from Beginning & End of a Cell

    That looks like it will do it

    Thank you both for your help!

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,945

    Re: Removing Spaces from Beginning & End of a Cell

    Happy to help

+ 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. Removing Spaces at the Beginning and/or End of a Text String
    By olives in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-09-2013, 06:55 PM
  2. Removing blank spaces from the beginning of cells
    By Research RN in forum Excel General
    Replies: 2
    Last Post: 06-17-2009, 11:39 AM
  3. How do I eliminate spaces/characters from the beginning of a cell
    By A Waller in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. How do I eliminate spaces/characters from the beginning of a cell
    By A Waller in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. How do I eliminate spaces/characters from the beginning of a cell
    By A Waller in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 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