+ Reply to Thread
Results 1 to 8 of 8

Remove consecutive spaces and replace with single comma

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Remove consecutive spaces and replace with single comma

    Have a list of names. For a majority of names the cell will contain the persons last name; followed by 2 or more spaces; followed by the first name. What I would like to accomplish is to remove in case in which there are two or more consecutive spaces and replace all with a comma and single space. Example of output below

    original data "ANDERSON MICHAEL"

    replace with "ANDERSON, MICHAEL"

    Is this possible with a formula or do I need to use VBA. I have attached a small sample in column A and the desired results in column B.

    Thanks
    Attached Files Attached Files

  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: Remove consecutive spaces and replace with single comma

    Enter formula in B2 and copy down

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    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
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Remove consecutive spaces and replace with single comma

    It is close to what I need but not quite there. For example, it is changing the following:

    Original data: "ANDERSON JR PATRICK"
    Updated data: "ANDERSON, JR PATRICK"
    Desired data: "ANDERSON JR, PATRICK"

    I only need to replace if there is a string of 2 or more consecutive spaces. I also have the following in the list

    Original data: "JOHN G ANDERSON FAMILY TRUST"
    Desired data: no change as there is no occurrence of 2 consecutive spaces.

    Thanks

  4. #4
    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,933

    Re: Remove consecutive spaces and replace with single comma

    If you are gpoing to provide a sample workbook for us to work with, you should remove the protection on it
    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

  5. #5
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Remove consecutive spaces and replace with single comma

    I didn't see any protect status on the first workbook attached. Was there a password on the first one? I'm reattaching per your comment. Thanks
    Attached Files Attached Files

  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: Remove consecutive spaces and replace with single comma

    Try this now. It should be somewhat better than the first. However, I don't see the way to find a logic for "ANDERSON FAMILY TRUST" and "MARCELLA J CLIENT GRANDCHILDRENS ED TRUST" unless I include word "TRUST" in search.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Remove consecutive spaces and replace with single comma

    You put me on the correct path with the SUBSTITUTE function; which I don't use it too often. I was able to modify formula using an if statement to figure out where the 2 consecutive spaces started in the string. Add in an IFERROR function; gets me to the end result. Thanks

    Please Login or Register  to view this content.

  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: Remove consecutive spaces and replace with single comma

    Excellent! Thanks for the feedback

+ 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 spaces and replace with comma.
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2013, 01:01 PM
  2. [SOLVED] Concatenate rows into single cell, but remove last comma from row
    By djm601 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2013, 09:45 AM
  3. [SOLVED] Replacing double spaces with single spaces
    By EdWoods in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-15-2013, 01:20 AM
  4. Find and remove all text to the left of last comma (including comma) in a cell
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-05-2013, 08:47 AM
  5. Using the Replace to remove Spaces in a Number
    By TWent in forum Excel General
    Replies: 5
    Last Post: 05-09-2011, 02:34 PM
  6. replace the comma separator to a dot and dot to a comma at the same time
    By barkiny in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2010, 05:42 PM
  7. How do I remove single spaces between words in spreadsheet?
    By spacecadet in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2007, 11:50 AM
  8. Remove single spaces
    By Bruno in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-27-2005, 11:05 AM

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