+ Reply to Thread
Results 1 to 14 of 14

Replacing double spaces with single spaces

  1. #1
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Replacing double spaces with single spaces

    Hi,

    This problem seems so easy to fix but I'm doing something wrong and I just can't figure it out.

    I have a macro that generates text (actually Amounts as Numbers to Amounts as Text).

    However in some cases it inserts double spaces, which I'd like to remove.

    I can use the "substitute" formula in the worksheet, however I'd rather fix the problem from within the macro. Is there a simple way to do this?

    Thanks, and sorry for being so dumb. Must be the alcohol finally taking effect after all these years!


    Cheers, Paul.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Replacing double spaces with single spaces

    Please provide the code so that we can have a look to fix it


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    Okay, here it is.

    When I put in (say) 3000, it has double spaces before the word "dollar". If I put in (say) 3210, it's fine.

    Please Login or Register  to view this content.
    Last edited by EdWoods; 04-15-2013 at 01:04 AM.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Replacing double spaces with single spaces

    Replace function is similar to Substitute function.

    However WorksheetFunction.Trim method should do it
    e.g
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    They're not leading or trailing spaces, there in the middle of the string...

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Replacing double spaces with single spaces

    You are talking about which function? with which value its getting more spaces?

  7. #7
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Replacing double spaces with single spaces

    Try changing line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Alf

  8. #8
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    As I mentioned before,

    When I put in (say) 3000, it has double spaces before the word "dollar". If I put in (say) 3210, it's fine.

  9. #9
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    Tried doing that, Alf. It mucks it up, having no spaces before the word "Dollar" when I put in (say) 3210.

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Replacing double spaces with single spaces

    I believe you got the solution in Post #7

  11. #11
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    Quote Originally Posted by :) Sixthsense :) View Post
    I believe you got the solution in Post #7
    Nope, unfortunately not. It then puts NO space if I type in (say) 3210.

  12. #12
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    Sorry, but I'm probably not explaining myself correctly.

    I don't want to mess with the main body of the code (tried that) as apart from the double spaces, it works well.

    All I want to do is insert some simple(?) code at the end of the SpellNumber function, after the line

    Please Login or Register  to view this content.
    to reformat SpellNumber text to remove double spaces IF they exist. Is it InString/Substitute or something along those lines?

  13. #13
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Replacing double spaces with single spaces

    Try Replacing

    Please Login or Register  to view this content.
    With

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    09-29-2011
    Location
    ɹǝpun uʍop
    MS-Off Ver
    365
    Posts
    250

    Re: Replacing double spaces with single spaces

    Quote Originally Posted by :) Sixthsense :) View Post
    Try Replacing

    Please Login or Register  to view this content.
    With

    Please Login or Register  to view this content.
    Awesome! Fixed. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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