+ Reply to Thread
Results 1 to 7 of 7

Replace spaces of more than one with a comma [RESOLVED] and a space

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    53

    Replace spaces of more than one with a comma [RESOLVED] and a space

    I have a spreadsheet of data pasted from a SQL database. The address field (column) contains multiple spaces between the address lines of text. The number of spaces between them varies in length. In order to perform a text-to-columns, I want to put a comma between each address line.

    I have managed to replace every space with one space using a 'TRIM(SUBSTITUTE' formula but cannot get the commas in where I want them.

    See attached
    Attached Files Attached Files
    Last edited by mattc_uk; 09-26-2022 at 12:00 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,539

    Re: Replace spaces of more than one with a comma and a space

    This works with the specific example.

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


    Can't guarantee it will work for all variations.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    53

    Re: Replace spaces of more than one with a comma and a space

    Thanks TMS. Unfortunately I have many variations to contend with and this formula will not resolve it. I've updated the spreadsheet to reflect more examples.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Replace spaces of more than one with a comma and a space

    IF you have upgraded at AT LEAST Excel 2013 AND are using a PC... in B1, copied across & down:

    =IFERROR(FILTERXML("<A><B>"&SUBSTITUTE($A2," ","</B><B>")&"</B></A>","//B[count(node())>0]["&COLUMNS($B1:B1)&"]"),"")

    If you have O365, it can be done even more neatly. Please check & amend your profile as needed.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,947

    Re: Replace spaces of more than one with a comma and a space

    Please Login or Register  to view this content.
    =add_CS(A2)
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  6. #6
    Registered User
    Join Date
    09-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    53

    Re: Replace spaces of more than one with a comma and a space

    Fantastic John, that did the trick!

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Replace spaces of more than one with a comma [RESOLVED] and a space

    Incidentally, ARE you still using Excel 2010?

+ 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] replace two spaces with only one space
    By MaartenRo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2021, 06:14 AM
  2. Replace SPACE with COMMA Unless preceded by a number or specific text
    By bluemanuk1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-18-2021, 03:52 PM
  3. [SOLVED] Replace any number of spaces with comma
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-24-2017, 07:47 AM
  4. [SOLVED] Remove consecutive spaces and replace with single comma
    By maacmaac in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-11-2015, 05:20 PM
  5. [SOLVED] Replace space to comma
    By rarementality in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2014, 09:15 AM
  6. [SOLVED] replace multiple spaces with one space to parse text
    By goodmma in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-20-2013, 06:21 PM
  7. [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

Tags for this Thread

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