Changing the thousands separator in VBA

  • Hi,
    I'm having trouble with this code:


    There are 9 modules like this one.
    When i run code to copy data(G27:G30), and go to the other workbook to paste data, paste code in other book:

    Code
    Private Sub pASTE_SPECIAL()
     On Error GoTo ifERROR
     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
     SkipBlanks:=False, Transpose:=True
    ifERROR:
     Exit Sub
     End Sub


    then i get error in excel turning coma decimal separator(EUROPA) into dot( . ) !!!


    [ATTACH=CONFIG]69162[/ATTACH][ATTACH=CONFIG]69163[/ATTACH]


    also posted here: https://answers.microsoft.com/…-b478-51a23fd44bf2?page=2

  • Re: Coma decimal separator turns in dot after Copy code?


    I don't have Office in my language. Is there a code for preserving regional formats like FMT , i don't know....

  • Re: Comma decimal separator turns into dot after Copy code?


    maybe this insert into sheet :



    NO no this is for forms. Sorry my bad


    Maybe this: Problem with Val, but i don't have any Val in code:)
    ""The problem is not in the currency datatype, but in the Val function.


    You used it completely unnecessary here.


    Val expects a string as parameter. VB will convert the value to a string for you, and will use the regional settings for this. If the decimal seperator is a comma, the string will be "23,44"


    Val however, is not regional settings aware, and will only recognize a point as decimal seperator. So it will stop after 23.


    In this case there is no reason to use Val. Just remove it. It only causes an extra implicit conversion (because the parameter is not a string), an exptra function call (Val is not necessary), and a second implicit conversion (Val returns a double and not a decimal)


    Your assigment will be
    Curr = 23.44


    Or if you want to be precise, you can use the currency declaration character, so no implicit conversion will occur anymore.


    Curr = [email protected]""

  • Re: Comma decimal separator turns into dot after Copy code?


    More codes from workbooks, i'm so sorry ozgrid :(






    Workbook 2nd:

    Code
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
        If ActiveCell.Column() > 21 Or ActiveCell.Row() > 61 Or ActiveCell.Row() = 1 Then
        GoTo ifERROR
        Else
        Application.ScreenUpdating = True
    ifERROR:
        End If
    End Sub



    Code
    Private Sub pASTE_SPECIAL()
     On Error GoTo ifERROR
     Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
     SkipBlanks:=False, Transpose:=True
    ifERROR:
     Exit Sub
     End Sub




    When ERROR occur i was using: Book1 (Macro1_SORT_LTV Macro, Macro8_SELECT_S14 Macro), book2 (Private Sub Workbook_SheetSelectionChange, move_right Macro, move_left Macro and print_report Macro).


    Error isn't sudden, it appears after a while(2-3-4 hours) :(

  • Re: Comma decimal separator turns into dot after Copy code?


    Where to insert into code? What about =FMT( .... something like that, code?

  • Re: Comma decimal separator turns into dot after Copy code?



    I already unchecked File>Options>Advanced> UseSystemProperties. I hope this modified code will not reset setting to default!? So far no error. Also testing w Excel2007. Maybe, problem might be in Office Outlook 2013, i have open three apps in taskbar, Outlook 2013 mail, Excel2013 wb1, and workbook2. Maybe there is some setting in Outlook witch resets mine Excel(File>Options>Advanced>UseSystemSeparator) setting?
    Also to mention, range G27:G30(and others SELECTmacros) is General setting with comma decimal separator.
    Thanks in advance and for love in Excel. :)


    I forggot to mention, when error was, numerical keyboard comma, was'nt working only inside Office, alphanumerical comma was working normally.

  • Re: Comma decimal separator turns into dot after Copy code?


    ERROR again. No help for me here :( :( I can't believe, i thought modifying that Copy code will solve ,,, but... :(

  • Re: Comma decimal separator turns into dot after Copy code?


    Maybe someware need to insert Application.EnableEvents=False ?? :smash:

  • Re: Comma decimal separator turns into dot after Copy code?


    I figured out. Problem is in second Workbook print code. After i print report, then i get comma error.
    But, question is how to fix it??


    And this code uncheck my FILE>OPTIONS>ADVANCE setting [ATTACH=CONFIG]69498[/ATTACH]

  • Re: Comma decimal separator turns into dot after Copy code?


    Please, OzGrid, may I upload workbook.xlsm ? Please.


    It is so weird problem. After I print report, I just lose european keyboard layout, numerical side of keyboard, comma goes into dot. But only inside Excel, not Outlook, not inside Windows :( :?:
    And only after printing on paper. When I choose to cancel print in PrintPreview there is no error.

  • Re: Comma decimal separator dot


    Please, someone on this beautiful site, maybe i need code to unlock and then lock again sheet? How to insert in Sub, function to unlock and lock sheet? I probably forggot to mention, List2(eng. Sheet2) is password protected sheet. In that sheet i unlocked working cells, but rest of the sheet is locked!

    Code
    Function UnProtectSheet()  
        'UnProtect Method with a password passed  
            Worksheets("Sheet1").Unprotect ("Vishwa123")  
    End Function



    NO NO, problem still persist, I unlocked all sheets and tried to print, and error again. Again comma from numerical keyboard turned into dot! AARRRRRGGGHHHHH!!
    ________________________________________________________________________________________________________________________



    I figured out after three months. Problem is in PrintPreview, but WHYYY MICROSOFT, WHY!

    Code
    '  In case there is no printing device:
             On Error Resume Next
             Application.Dialogs(xlDialogPrinterSetup).Show
             Selection.PrintOut Preview:=True


    When i set Selection.PrintOut Preview:=False everything is fine, no error.
    But, why! I really need print preview :( ;(

  • Re: Comma decimal separator dot


    I figured out after three months. Problem is in PrintPreview, but WHYYY MICROSOFT, WHY!

    Code
    '  In case there is no printing device:
             On Error Resume Next
             Application.Dialogs(xlDialogPrinterSetup).Show
             Selection.PrintOut Preview:=True


    When i set Selection.PrintOut Preview:=False everything is fine, no error.
    But, why! I really need print preview :( ;([/QUOTE]


    Bump :(

  • Re: Changing the thousands separator in VBA


    Also tried with my language(excel), no help for me. Error again. Every time i print on paper there is error, comma turns into point . But when i only PrintPreview and exit(no print on paper) there is no error, all good! Bug in Excel :(
    [ATTACH=CONFIG]70259[/ATTACH]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!