+ Reply to Thread
Results 1 to 11 of 11

How to make number format remain same even if vba executed from different geolocations?

  1. #1
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    How to make number format remain same even if vba executed from different geolocations?

    Hi Experts,

    I have a range for which number format should be applied and using below VBA:

    Please Login or Register  to view this content.
    It's working fine if am executing from US/UK location but if the same vba executed from different geo-location (Say for example Romania, its taking "lei" as currency instead of "$" symbol).

    I really appreciate any help provided.

    Regards,
    Richa
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: Need VBA to apply number format decimal dot and comma

    ............
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Richavlaues; 08-18-2016 at 04:43 PM.

  3. #3
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: Need VBA to apply number format decimal dot and comma

    Hi All,

    After doing some research and lot of trial and error method, I tried to apply number format for the range and was able to apply currency symbol but am not getting how to replace dot with comma.

    Have updated the macro with buttons that shows if macro executed from different locations.

    Please Login or Register  to view this content.
    I have changed system settings in Windows 7 --> "Region and Language" --> Romania (since currency symbol and number format "lei 0.000,00" is different than US "$ 0,000.00").

    Attachment 475998

    So would like to know how to change format from comma to dot.

    Any help greatly appreciated.

    Regards,
    Richa
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to make number format remain same even if vba executed from different geolocations

    Hello Richa,

    The answer is you can and you can not change these values. Any changes you make in VBA will be undone by Excel. You're probably asking "Why?".

    Creating workbooks that will function internationally is not easy. There are many layers to this problem. The system sets the default regional and language settings during installation. This includes the basic formatting for numbers, dates, time, and money based on the user's locale. It would be great if this was all that needed to changed. Wait for it... But, it isn't that easy.

    Applications, like Excel, can change these settings according to their own rules. To make things even more interesting the individual user accounts have default settings for these formats also. It does not stop here though. Individual threads can modify these format settings as can certain Windows controls like CombBoxes and ListBoxes. Yeah, in a word it is a mess.

    To change these formats requires using the Windows API. This adds a new layer to our onion because these are low level system calls. Documentation exists but it not written for the average user and requires an understanding of Windows at the system level. Error checking is almost non existent, which it makes things exciting. If you do not know what you are doing these calls, you can royally screw the pooch and crash your system. Possibly, even it damage it.

    Here is sample of some of the API calls and constants used for changing the money formatting.
    Please Login or Register  to view this content.
    A few years ago, I created a Gregorian Calendar that would display the months and days in the user's local language and allows the user to change date and time formatting. The calendar was displayed on a VBA UserForm. As long as the UserForm is displayed in the default state (Modal), the UserFrom can change the cell formatting. Modal windows or dialog boxes prevent the user from interacting with the application. Once the window is dismissed, the user can the again interact with the application. This method works because the modal thread is not a part of the Excel application. However, the VBA thread is and once focus is switched back to Excel from VBA then Excel will reset to it format settings.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: How to make number format remain same even if vba executed from different geolocations

    Hi Leith,

    Thanks for providing detailed explanation on how to make excel work internationally and also for mentioning its constraints, limitations and workaround. I really appreciate it.

    I was having a thought if there is an option to change locale (something defining at top of vba similar to option explicit level or public variable) to make vba to apply formats to locale that user wants.

    For example:
    Please Login or Register  to view this content.
    or similar to this:
    Please Login or Register  to view this content.
    Then no matter from where user executes the macro, it should apply US formats and once the macro is executed, user will have normal settings as before. Does VBA have any commands or functions to do this?

    Am actually worried in changing system settings on user's machine. What if something goes wrong?

    Regards,
    Richa

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: How to make number format remain same even if vba executed from different geolocations

    Why do you care what the user sees as thousands and decimal separators? It doesn't affect the value of the cell in any way.

    IMO you should never change the user's settings.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to make number format remain same even if vba executed from different geolocations

    Hello Richa,

    I agree with rorya you should not change the user's settings. Unless you convert the number into a formatted string, I don't know of any other way to accomplish your goal. Of course doing so would prevent you from doing any mathematical operations on the converted numbers.

  8. #8
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: How to make number format remain same even if vba executed from different geolocations

    Hi Leith and Rorya,

    Thanks for prompt response and am sorry if my question or description confused the requirement am looking for. So here's exactly the scenario that am looking for:
    1. I have written macro that works with US currency symbol and "US decimal and comma separator format" (I will call this as "format" for easier understanding). If am in US and executing the macro from any US location, the format and currency is fine.
    2. Now what I want to do is: If the same macro is executed from different location (where currency and format differs. For example Brazil, Romania etc), and execute the macro for US location, it's taking format and currency values based on the user location ie., either Brazil or Romania but not applying US currency and formats. This is huge issue for me as I need currency as $ and format as XX,XXX.XX
    3. Though I have used code to apply US format "Worksheets("Sheet1").Range("A11:B14").NumberFormat = "[$$-409]#,##0.00"", macro is still applying Brazil/Romania currency and format as XX.XXX,XX

    In simple words, macro should apply US currency and number formats no matter from which geo location the macro gets executed.

    Once I achieve this, I want to do some more additional steps such as having select case statements for different location. For example: If US, apply US currency formats else if India, apply India currency and format etc.,

    I really appreciate any help provided.

    Regards,
    Richa

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: How to make number format remain same even if vba executed from different geolocations

    Again, why does your macro care about the format of the numbers?

  10. #10
    Registered User
    Join Date
    02-19-2016
    Location
    US
    MS-Off Ver
    2007
    Posts
    74

    Re: How to make number format remain same even if vba executed from different geolocations

    Hi Rorya,

    Am generating table in excel and inserting those table in Word template and the format has to be in the region specific format. If am running macro from Romania and is for US location, then it should have comma and then decimal; no matter from which geo location the macro is executed. If the same macro is executed for Brazil location from US, then it should have decimal and comma format. Right now format is getting override by location from where macro is executed instead of the location for which it has to be executed. For example if am executing macro from Romania (where the format is decimal and comma) to US location (where format is comma and decimal), macro still applying Romanian format (decimal and comma) but I want it to apply US format ie., comma and decimal.

    Its simple concept but also quite confusing. Sorry.

    Regards,
    Richa

  11. #11
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    How to make number format remain same for different geolocations. VBA Comer Point Bollox

    Hi Richavlaues,

    The following does not directly relate to or answer your specific problem. It could help , however in the endless battle against Excel changing Number formats in regard to the decimal and thousand separator_.....
    Quote Originally Posted by Richavlaues View Post
    ....how to change format from comma to dot......
    _.........
    _.......
    I use German and English Excel and, for example scrape websites in English and German
    I battle endlessly against the problem.
    I have come to the conclusion it is impossible to completely get over the problem
    I believe it will always come up
    As Leith intimated it is a minefield and there are endless factors affecting, such that there will never be any one solution that always works.
    However, amongst the weapons I use in the fights against Excel, I have a function which I wrote which has on many occasions saved the day, and has actually, proved fairly bullet proof.

    It is most used when I receive a “number” , to which I have no control over the source and in addition, mostly, find I am unable, consistently to control Excel to manipulate it without , seemingly, at will, changing a comer to a point, or a decimal separator to a thousand separator.

    Briefly, the method is simple.

    I may receive for example a “Number”, as example:
    1.200,001
    or
    1,200.001

    In words this number is
    One thousand two hundred , and one thousandths
    or
    One thousand two hundred and 1/1000

    My function will take the number as a string. ( VBA is quite kind here, generally, I find, as it will both take and use a “Number” as a string happily in calculations, provided it “looks” like a number. )***
    I simply split by the last separator, regardless of what it is, and ignore all others, so for example in this example I obtain
    “1200” and “001”
    The code then uses the first string to give directly a simple whole number
    1200
    Further, a number will be created from the second string , ( for this example ) in this fashion:
    =1 / 1000

    These numbers are then added mathematically.

    _...............
    The result of this is that VBA has created the number, in the way I want it. I then have found, up until now, that any pasting out anywhere , or further calculations have come out as I wish them to.
    Exactly where and when I use the function can vary. In some cases I will use it more than once, “just to be on the safe side ( “belt and braces “ )” .

    The point is that, as VBA created the number itself, it seems then to further behave itself, making the necessary formatting .
    _............

    I have not concerned myself too much with how a number “looks” in an Excel Spreadsheet. I usually find if my Function has done its job properly, which up until now it appears to have done, then pasting out to, and importantly, later taking from , a Spreadsheet cell, will “behave itself”

    I have not done endless tests on my function, so any comments or suggestions for improvement are welcome. Up until now it has never failed me.

    Function Code and a demo calling Code

    Please Login or Register  to view this content.


    Alan


    Ref
    http://www.eileenslounge.com/viewtop...177530#p177528
    http://www.mrexcel.com/forum/questio...l-problem.html



    *** P.s.
    Quote Originally Posted by Leith Ross View Post
    ..... convert the number into a formatted string, I don't know of any other way to accomplish your goal. Of course doing so would prevent you from doing any mathematical operations on the converted numbers.
    ... I am not quite sure I follow this. I have found VBA and Excel very tolerant of taking string which “look” like a number as a number.. In fact I routinely use a string variable , if I have the chance, in any code where I am using a number or wanting to manipulate numbers. Up until now I have only seen advantages. – Such as reducing my problems associated with the issues of this Thread, and allowing easier manipulation of , and use of, the VBA Strings Functions. Sometimes to be on the safe side, in a calculation, I may do a ( pseudo code ) _...
    Number = ConvertToDouble(NumberInStringVariable)
    _.. however it has never proved necessary
    Last edited by Doc.AElstein; 09-09-2016 at 11:31 AM.
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

+ 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. Replies: 2
    Last Post: 07-28-2016, 08:12 AM
  2. Replies: 14
    Last Post: 05-26-2016, 12:00 PM
  3. [SOLVED] need to make text into number format
    By stvbrown2184 in forum Excel General
    Replies: 3
    Last Post: 05-20-2014, 09:42 AM
  4. Replies: 5
    Last Post: 06-26-2009, 12:42 PM
  5. Make comments remain
    By Obfuscated in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-16-2009, 11:13 PM
  6. How can I make the box remain empty instead of N/A#
    By VegasBurger in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-14-2006, 02:20 PM
  7. make:Custom Number Format
    By robertjtucker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2006, 02:35 PM

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