+ Reply to Thread
Results 1 to 4 of 4

Getting decimal separator

Hybrid View

  1. #1
    Registered User
    Join Date
    09-18-2003
    Location
    Denmark, Europe
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    5

    Getting decimal separator

    I am developing an Excel application to be used in European countries that use different decimal separators (comma or period) and different 1000 separators (period and comma). Therefore I need a system call from VBA that can tell me which decimal separator is actually used.

    In other words, how do I in VBA ask the system for the decimal separator?
    Helge V. Larsen

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Getting decimal separator

    See International Settings.

    Debug.Print Application.International(xlDecimalSeparator)
    FWIW - remember also the likes of FormulaLocal / FormulaR1C1Local ...

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: Getting decimal separator

    Application.DecimalSeparator
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    10-01-2008
    Location
    Piracicaba, SP
    Posts
    6

    Re: Getting decimal separator

    I've tested both the suggestions above with Excel 2003, on a computer with standard system settings for Brazil:

    Application.DecimalSeparator
    always returns the character in the textbox for Decimal separator of the International tab of the Options form (regardless of whether the box for use system separators is checked or not).

    Application.International(xlDecimalSeparator)
    returns the system wide decimal separator.

    I have found this to be very important when working with code to modify formulas (range.formula), in which the decimal separator must always be ".", and not the system wide decimal separator. Here's some illustrative code:

    Sub formula_edit()
    
    Dim str_formula As String, block_formula As String, str_address As String
    Dim str_value As String, str_10 As String, str_value_dot As String
    Dim str_formula_1 As String, str_formula_2 As String
    
        If Application.UseSystemSeparators Then
            str_10 = Application.International(xlDecimalSeparator)
        Else
            str_10 = Application.DecimalSeparator
        End If
        
        With ThisWorkbook.ActiveSheet
            With Selection
                str_formula = .Formula
                str_address = .Cells(1, 0).Address(rowabsolute:=False, columnabsolute:=False)
                str_value = CStr(.Cells(1, 0).Value)
                str_value_dot = Replace(str_value, str_10, ".")
                str_formula_1 = Replace(str_formula, str_address, str_value)
                str_formula_2 = Replace(str_formula, str_address, str_value_dot)
            End With
            block_formula = "x" & str_formula
            With .Range("A6")
                On Error Resume Next
                .Cells(1, 5).Value = "test failed"
                .Cells(2, 5).Value = "test failed"
    '  precede with "x" to block formula evaluation on spreadsheet
                .Cells(1, 1).Value = "x" & str_formula
                .Cells(1, 2).Value = "x" & str_address
                .Cells(1, 3).Value = "x" & str_value
                .Cells(1, 4).Value = "x" & str_formula_1
                .Cells(1, 5).Formula = str_formula_1
                .Cells(2, 3).Value = "x" & Replace(str_value, str_10, ".")
                .Cells(2, 4).Value = "x" & str_formula_2
                .Cells(2, 5).Formula = str_formula_2
            End With
        End With
        
    End Sub

    With use system separators checked, and "." in the decimal separator box, I placed the value 2,36 ("," is my local system decimal separator) in cell D3, and the formula =D3*5,42 in cell E3. I then selected cell E3 and ran the macro above. Upon completion the contents of the cells were:

    HTML Code: 
    So for me:

    Application.DecimalSeparator

    Application.International(xlDecimalSeparator)


    Sincerely,

    Richard.

+ 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