+ Reply to Thread
Results 1 to 10 of 10

How to remove certain characters from a text string

  1. #1
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    How to remove certain characters from a text string

    Hello,

    I have a list of codes in column A of a worksheet. The codes in each cell are of varying length, containing spaces, numbers, and text.

    I'm wondering if there's a way to create a macro (or even better, if there's an existing formula) to simply go down the list and remove the very first and very last character in each cell of column A.

    For example, if cell A11 has "A56322 643 " (note the space at the end), B11 would read "56322 643" with the first character and the last space missing. Is this possible? I'm not very familiar with macros, especially those for editing text, so any help is greatly appreciated. Thank you all.

  2. #2
    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: How to remove certain characters from a text string

    Try this

    =TRIM(REPLACE(A11,1,1,""))
    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

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to remove certain characters from a text string

    Maybe:

    Please Login or Register  to view this content.
    Unable to test. Try on a copy first.

  4. #4
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: How to remove certain characters from a text string

    Alkey - thank you, this works very well. This will take care of removing the first character in the string - is there a way to remove the final character in the string? I can't guarantee that the final character will always be X spaces from the left, it will change depending on the cell.

    John, thank you as well for your VBA solution. The problem I'm having with the macro is that its removing the first character and the last, but isn't counting spaces as characters. For example, if I have "123 " (with a space on the right) in A2, it will return "2", instead of "23". Any thoughts?

    Thank you both again for your help.

  5. #5
    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: How to remove certain characters from a text string

    Trim Function that is in front of the formula will remove spaces from the left or right. If you need to remove all spaces please let know and I will adjust formula.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to remove certain characters from a text string

    Quote Originally Posted by Student1990 View Post
    Alkey - thank you, this works very well. This will take care of removing the first character in the string - is there a way to remove the final character in the string? I can't guarantee that the final character will always be X spaces from the left, it will change depending on the cell.

    John, thank you as well for your VBA solution. The problem I'm having with the macro is that its removing the first character and the last, but isn't counting spaces as characters. For example, if I have "123 " (with a space on the right) in A2, it will return "2", instead of "23". Any thoughts?

    Thank you both again for your help.
    It shouldn't do that. But if you could provide a sample, I can take a look.

  7. #7
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: How to remove certain characters from a text string

    Thanks for the advice! I think I better include an example and rephrase my issue a bit.

    The numbers that I want to trim down come from another program, and I think they come in as "text". There are always spaces at the beginning and at the end of the number. I've attached a workbook to demonstrate the issue.

    Column A contains the number I want to edit. In column B, I've tried a TRIM function, but that still leaves me with an unusable number. My goal is to be able to use the numbers in column A in simple calculations, for example, substracting A from the number in column C. As you can see, I get an error in column D when I attempt to do that calculation.

    If I manually go in an delete the space in front of and behind the number in column A, then the formula can read the number successfully. Is there an automated way to do this. TrimNumberSpaces.xlsx

  8. #8
    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: How to remove certain characters from a text string

    For this type spaces that you have in your spreadsheet you need this

    =SUBSTITUTE(A2,CHAR(160),"")

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to remove certain characters from a text string

    Never mind...duplicate solution...
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  10. #10
    Registered User
    Join Date
    07-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: How to remove certain characters from a text string

    Thanks to all for these solutions.

+ 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] Remove duplicate characters from a text string in a cell
    By sam99 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 09-22-2020, 06:10 PM
  2. [SOLVED] Remove certain characters from the end of a string only
    By mini_dutch28 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-20-2012, 01:04 PM
  3. Remove characters from a text string using a formula
    By duncrbrt in forum Excel General
    Replies: 1
    Last Post: 06-03-2005, 10:05 PM
  4. Replies: 1
    Last Post: 04-18-2005, 05:06 PM
  5. 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