+ Reply to Thread
Results 1 to 5 of 5

CDec: international syntax for argument string with decimals

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    71

    CDec: international syntax for argument string with decimals

    My Excel is set in English for everything (formula, interface, guide).
    My Windows is set with "," for decimal symbol and with "." for Digit grouping symbol in regional settings, as I live in Italy.

    If I write this code:
    Please Login or Register  to view this content.
    result is displayed as "12345678901234567050,123456789" (Variant/Decimal) in Locals window. Same if I msgbox it.

    If I use "." instead than ",", result is 12345678901234567000123456839.

    In VBA, when writing numbers (in form of numbers, not strings), I must use the english syntax i.e. "." for decimal symbol.

    I believe that that code of my example would run wrongly by a Windows with English regional settings.

    How can I (modify it to) make it run correctly with any regional settings?
    Last edited by 6diegodiego9; 07-05-2019 at 09:09 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: CDec: international syntax for argument string with decimals

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: CDec: international syntax for argument string with decimals

    You can easily test which decimal separator is currently used (on a computer where the excel file is open), by using:

    Please Login or Register  to view this content.
    so (it is not the solution for working code , just a demopnstration):
    Please Login or Register  to view this content.
    will always work as expected
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    01-10-2018
    Location
    Italy
    MS-Off Ver
    Excel 365 (2021-01)
    Posts
    71

    Re: CDec: international syntax for argument string with decimals

    Wonderful, thanks Kaper!

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,178

    Re: CDec: international syntax for argument string with decimals

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. [SOLVED] Constructed string and pas it as an argument
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-24-2015, 05:56 AM
  2. [SOLVED] Add values with 2 decimals in a string text
    By mils in forum Excel General
    Replies: 2
    Last Post: 05-26-2015, 11:20 AM
  3. [SOLVED] Blank CInt & Cdec textbox values with mismatch
    By johnny_p in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2015, 07:00 AM
  4. [SOLVED] stdev.p syntax: Number 2 Argument
    By Winship in forum Excel General
    Replies: 4
    Last Post: 02-21-2014, 04:38 PM
  5. Convert text to number cDec(xCell.Value)
    By LiLi1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2012, 01:49 PM
  6. Can I Put a Conditional Argument into a string?
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-23-2009, 07:10 PM
  7. Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

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