+ Reply to Thread
Results 1 to 6 of 6

How to remove white spaces from a phrase?

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    145

    How to remove white spaces from a phrase?

    I have a list of phrases in a single column, something like this:

    lower back pain
    back pain
    Earth
    back exercises
    upper back pain
    lower back exercises


    As you can see, some phrases can be a single word, and some can be several words.

    I need a solution (preferably a macro) that will delete all white spaces between the words, so that each phrase become a string of a few characters in a row, while leaving the single words phrases as is.
    After running the macro the list will look like this:

    lowerbackpain
    backpain
    Earth
    backexercises
    upperbackpain
    lowerbackexercises


    Any ideas?

  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 white spaces from a phrase?

    I know you are looking for VBA solution but here is how you can do it by formula


    =SUBSTITUTE(A1," ","")
    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 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
    44,445

    Re: How to remove white spaces from a phrase?

    Why do you need a macro? Just select the cells and do a global replace of space for nothing. That is, press this space bar once in the Find box and leave the Replace with box empty. Then do Replace All.

    If you want, you could record a macro while you do it?

    Regards, TMS
    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


  4. #4
    Forum Contributor
    Join Date
    05-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    145

    Re: How to remove white spaces from a phrase?

    Thanks a lot!
    Sami

    Quote Originally Posted by AlKey View Post
    I know you are looking for VBA solution but here is how you can do it by formula


    =SUBSTITUTE(A1," ","")

  5. #5
    Forum Contributor
    Join Date
    05-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    145

    Re: How to remove white spaces from a phrase?

    Thanks, didn't think about it!

    Quote Originally Posted by TMShucks View Post
    Why do you need a macro? Just select the cells and do a global replace of space for nothing. That is, press this space bar once in the Find box and leave the Replace with box empty. Then do Replace All.

    If you want, you could record a macro while you do it?

    Regards, TMS

  6. #6
    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
    44,445

    Re: How to remove white spaces from a phrase?

    You're welcome. Thanks for the rep.

+ 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. Replace white spaces with tab delimiter to creare table
    By thadacto in forum Word Programming / VBA / Macros
    Replies: 4
    Last Post: 12-01-2013, 03:56 PM
  2. Remove White Spaces from all cells
    By modest_16081982 in forum Excel General
    Replies: 18
    Last Post: 05-03-2013, 07:22 AM
  3. Replies: 2
    Last Post: 07-20-2012, 01:59 PM
  4. Copy cell value and delete white spaces?
    By gombi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-04-2010, 08:24 AM
  5. Remove white spaces in Back
    By dziw in forum Excel General
    Replies: 2
    Last Post: 07-19-2006, 01:55 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