+ Reply to Thread
Results 1 to 22 of 22

Replace dot with comma with macro

  1. #1
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Replace dot with comma with macro

    I've created a small macro to replace a dot with a comma sign, but it doesn't work in all the cells I want to make the replacement. See attached file.

    When pressing the button, the macro is supposed to replace the dot to a comma sign in the selected cell. In cells A3 and A4 it works, but in cells A1 and A2 the comma sign is placed after the decimals. I've tried to switch cell format between General and Number and also the number of decimals when using the Number format, but can't see any difference.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Replace dot with comma with macro

    Interesting. Your macro works in all cells for me.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Replace dot with comma with macro

    It won't work if you haven't selected the cells first

    The first two cells are formatted as Number, the next as General. This will affect the display
    Last edited by royUK; 03-11-2011 at 05:42 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Quote Originally Posted by royUK View Post
    It won't work if you haven't selected the cells first

    The first two cells are formatted as Number, the next as General. This will affect the display
    All the four cells have the General format before running the macro, but after selecting each cell and pressing the button I get the cell formats you describe. So from what I can see, the cells are identical by format and the same macro is used in all cells, I can't understand why the outcome differs???

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Replace dot with comma with macro

    I've tried re-formatting the cells within the code
    Please Login or Register  to view this content.
    This doesn't work for me but it could be my version of Excel

  6. #6
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Quote Originally Posted by royUK View Post
    I've tried re-formatting the cells within the code
    Please Login or Register  to view this content.
    This doesn't work for me but it could be my version of Excel

    It doesn't work for me neither.

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Replace dot with comma with macro

    What is your system separator set to?
    Is it the continental system 1.000,00 or the UK/USA system 1,000.00?

    What do you expect the result in each cell to return?

  8. #8
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Replace dot with comma with macro

    Hello Idde,

    I'm with Marcol here. You probably use regional language settings with different delimiters for decimal points than US or UK format (JBeaucaire is probably US and RoyUK is, well, UK).

    This will make it difficult to test your macro, unless someone uses exactly the same regional settings.

    Please take a look in your Windows Control Panel and let us know what these settings are. Then the helpers here can apply the same settings and inspect the file and the macro under the same premises.

    cheers,

  9. #9
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Quote Originally Posted by teylyn View Post
    Hello Idde,

    I'm with Marcol here. You probably use regional language settings with different delimiters for decimal points than US or UK format (JBeaucaire is probably US and RoyUK is, well, UK).

    This will make it difficult to test your macro, unless someone uses exactly the same regional settings.

    Please take a look in your Windows Control Panel and let us know what these settings are. Then the helpers here can apply the same settings and inspect the file and the macro under the same premises.

    cheers,

    Hi,

    See attached screenshot for language options.
    Attached Images Attached Images

  10. #10
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Replace dot with comma with macro

    OK, I've changed my settings to Swedish.

    I see the same thing and I do not have an explanation for it. Apparently, if there are more than two digits after the dot, replacing the dot with a comma will not result in those values retaining the decimal point at the position of the dot. Rather, when there are more than two characters after the replaced dot, the number will be interpreted as an integer.

    Strange .....

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Replace dot with comma with macro

    Aye. I had a problem like this when doing some work for a Danish company.
    There was a lot of trial and error to get it right and it was a while ago and I can't remember the final solution.

    Try this workbook, I'm not saying it will work for you, but if it throws errors when you open it post a screenshot of the result.
    Save the file on your system and post the copy and I'll see if that jogs my memory,
    The problem always recurred after saving on another system.

    Cheers

    [EDIT]
    There will possibly also be a problem with formula, the delimiter you are likely to be using will be ";" (semi-colon) not "," (comma)
    Attached Files Attached Files
    Last edited by Marcol; 03-14-2011 at 10:18 AM. Reason: Forgot the attachment

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Replace dot with comma with macro

    See what happens if the rightmost number isn't zero.



  13. #13
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Quote Originally Posted by Marcol View Post
    Aye. I had a problem like this when doing some work for a Danish company.
    There was a lot of trial and error to get it right and it was a while ago and I can't remember the final solution.

    Try this workbook, I'm not saying it will work for you, but if it throws errors when you open it post a screenshot of the result.
    Save the file on your system and post the copy and I'll see if that jogs my memory,
    The problem always recurred after saving on another system.

    Cheers

    [EDIT]
    There will possibly also be a problem with formula, the delimiter you are likely to be using will be ";" (semi-colon) not "," (comma)

    I didn't get any errors when I opened the workbook and from what I could see it looked OK. I saved it to my desktop and attached it below.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Quote Originally Posted by snb View Post
    See what happens if the rightmost number isn't zero.
    Hi,

    It didn't make any difference for me.

  15. #15
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Replace dot with comma with macro

    I think the problem could be with the decimal separator settings in Excel.

    Check this
    Office Button > Excel Options > Advanced
    What are your DecimalSeparator and ThousandsSeparator set to?

    Try this
    Please Login or Register  to view this content.
    The loop is just to see if you get the same result as me.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  16. #16
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Quote Originally Posted by Marcol View Post
    I think the problem could be with the decimal separator settings in Excel.

    Check this
    Office Button > Excel Options > Advanced
    What are your DecimalSeparator and ThousandsSeparator set to?

    Try this
    Please Login or Register  to view this content.
    The loop is just to see if you get the same result as me.
    I used your code, but there was no difference, 63.0000 became 630000,0000.

    I have the Use system separators checked, with a comma as Decimal separator and a dot as Thousands separator in each gray marked field.

  17. #17
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Replace dot with comma with macro

    I have set my m/c to Swedish and the separators as you described.

    The attached is a copy of your original file.

    Does this do what you are looking for?
    Attached Files Attached Files

  18. #18
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Replace dot with comma with macro

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    03-11-2011
    Location
    Gävle, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Replace dot with comma with macro

    Marcol and snb,

    Thanks for the help, but I still get, for example, the first value to be 630000, instead of 63,0000 that I want :S

  20. #20
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Replace dot with comma with macro

    Here you are:
    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by snb; 03-15-2011 at 09:46 AM.

  21. #21
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Replace dot with comma with macro

    romperstomper
    Where are you when we need you...

  22. #22
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Replace dot with comma with macro

    You could use:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

+ 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