+ Reply to Thread
Results 1 to 21 of 21

Date Format Change in other systems and due to that Macro doesn't work properly

  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Date Format Change in other systems and due to that Macro doesn't work properly

    Hello Guys,

    I am having quite a hard time to solve this issue as it's working seamlessly on my system and any other system which has system date format in US, i.e. mm-dd-yyyy, however, the issue is that client is from Europe and their system date formats are different and can be anything, e.g. dd-mm-yyyy or anything.

    I tried everything to keep the date format constant but it's futul and generating the issue on client's system because the process doesn't run.

    Here in the attached workbook "Main" sheet, there is a button called "Generate Billing/Contract" when it's clicked, an userform pop-up with 2 option buttons, 1st is for Billing Invoice & 2nd for Rent Agreement, after selecting whichever, there is userform which requires to be filled with the information from the "Reservation_Raw" sheet and create the Invoice/Agreement accordingly but issue as I explained, arise when system date format is other than USA standard date format because the data is also in US date format and in client's system, after selecting "Check In" date, they get "Check Out" date blank and other fields are also blank because all the fields are interconnected.

    Below is the sample of code where issue arise:

    Please Login or Register  to view this content.
    I tried to attach the workbook also for your kind perusal but I am not able to as attachment option is not working while posting this issue here but if you need, please let me know how can I provide the workbook.

    Kindly help me out in this as being stuck for last some weeks and due to this project is not finished.

    Thanks a lot.
    Last edited by brajpalshishodia; 07-08-2019 at 08:48 PM.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Here's how to attach a file
    Attached Files Attached Files
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Hello Keebellah,

    Thanks a lot for sharing the SOP for attaching the file, it was quite helpful and clear.

    I followed the instructions and was able to attach the file.

    Here you will see "Generate Billing/Contact" button, when it's clicked, userform opens with 2 option buttons for Billing Invoice/Rent Agreement, select any one.

    This issue is with Check IN and Check Out date fields.

    It works fine with US date format, i.e. m/dd/yyyy h;mm:ss am/pm@ but when system local regional settings are different from US format then it creates issue.

    You will see I have used FMT function in Module "Macro 1" and using standard format but it is also not working.

    Kindly help, it will be highly appreciated.

    Best Regards.
    Attached Files Attached Files

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Got the file will see what I can do for you

  5. #5
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    That's great, will wait, Thanks a lot

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Some links that you should look at:
    https://superuser.com/questions/7303...erns-in-formul
    https://powerspreadsheets.com/vba-format-date/
    https://bettersolutions.com/vba/macr...n-language.htm
    These might give you some ideas.
    I'll check what I have as code in my acrhives

  7. #7
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Yes Keebellah, Thanks for sharing the links, all these were part of my research in the process to rectify this date format issue and used "FMT" function in my code referring the 1st link, however, user has to change their system date format at least once to make it working, it won't work when user will open the file. He will have to go to Control Panel and then just some modification in Date and Time field, isn't necessary to make it US Format and when come back after clicking on Apply button, it start working.

    Strange but this is happening.

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    One thing that you must avoid in all cases is that users need to make changes to their settings for your app to work.
    This YOU have to solve inside the VBA, dates may be shown in any format as long as you can still person the necessary calculations. In one case the AM/PM will be visible and others not.
    You have to read the user's system settings but not make them change it for your application to work.

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Personally whenever possible I use dd-mmm-yyyy (the important part being mmm) as my date format in sheets. Otherwise I often run into problems where the month/day are mis-interpreted. By using the letters for the month, excel can't get confused as to which number is the month vs. the day.

    When I changed the format of your date/time columns (B:D) in the Reservation sheet to "dd-mmm-yyyy h:mm" it seemed to work with different system date formats.
    Last edited by Arkadi; 07-10-2019 at 08:41 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  10. #10
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Hello Keebellah,

    Yes Sir, that's the same thing I also want to achieve that user doesn't have to refer his system settings at all and it should work for any type of date format but not able to do the same and looking for the help here.

  11. #11
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Hello Arkadi,

    Did you changed the date format in Reservation tab or Reservation_Raw tab as for creating Billing Invoice & Rent Agreement, Reservation_Raw tab is used. One more thing I want to know that how were you able to verify that it's working for different system date format. You verified it on any different system or on your system by changing the date format through Control Panel.

    Many Thanks for your reply though.

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    I guess in my test I forgot to close/re-open excel when I changed date formats. Will keep looking at a solution, but what I tried before did not work.

  13. #13
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Okay...appreciate your concern to find the solution, that will be great relief.
    Best Regards.

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    I would like to point out that the date format is only a visual interpretation,
    did/mmm/yyyy makes what you see clear and will display the date January 3, 2019 either as 03/jan/2019 but the system date might interpret it as March 1, 2019 and show the result in the cell as 01/mar/2019
    The only way to avoid confusion is to always use the serial date value so you know for sure what date is being used
    I struggled with this for years but solved it by always making sure that the date was a serial value (also with the time value) and the format the cell or text box accordingly for the visual part
    Hope i’ve been able to explain myself

  15. #15
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Hi All,

    Just a general comment regarding dates:

    Dates and Times are STORED as numbers on a worksheet, but are DISPLAYED in whichever format the User has selected.

    So far, so good, BUT once a numeric date value is sent to a TextBox, ComboBox, Dropdown List etc. the value becomes a STRING and must be processed appropriately so that it is "sent back to Excel" as a numeric value for entry into a worksheet cell, calculation, use in a filter etc.

    Regards,

    Greg M

  16. #16
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    @gregM... Exactly! And the op is using tucked away ranges, textboxes, comboboxes... Hard to follow it all and find the best solution. In addition the format function (FMT) he is using formats differently than the cells. Tbh I'm surprised it works even in one regional format

  17. #17
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    True, and that's why I said that you should always make sure whatever you process make sure you bring it back to the correct numeric (serial) value, requires extra code but that's the only way to get it working.
    A textbox on a userform is okay to show what the user has selected but the calendar should at all time be used to select a date and a date variable to hold the selected date, not just the textbox.
    I'll extract my data form from a file I have and attach it later, explains it better, tells more than all the words

  18. #18
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    I didn't find the correct file but I did find my vba module that solves some issues.
    Some reference is in the code as to it's origin but som things were edited by me.
    Place this module in the VBA Project, and then use the following syntax in the vba to format the date (no time just date)

    Please Login or Register  to view this content.
    FormatDate is the string result depending on the system's settings.

    Take a look and see if you can implement it, you can always edit the vba module to include the time part
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Hello Keebellah,

    Thanks a ton for sharing DateModuleInternational.Zip and the suggestion to use date as serial number not as text in the code, it was really helpful and finally solved the issue with which I was struggling a lot.

    Highly Highly Highly appreciate for your patience with this issue and provide the solution.

    I would like thank Arkadi, Greg M for their valuable inputs as well.

    All in all it has been a great learning for future.

    Best Regards,
    Brajpal Shishodia

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    You're very welcome, that's what we all hope to achieve, pass on ideas we ourselves found and reused or modified.
    Always learning, never too old to learn

  21. #21
    Registered User
    Join Date
    09-05-2012
    Location
    Ghaziabad
    MS-Off Ver
    Excel 2003,07,10,13
    Posts
    52

    Re: Date Format Change in other systems and due to that Macro doesn't work properly

    Yes, can't agree more, therefore, sharing the working template here if anyone need in future to get the solution.

    Many Thanks again.

    Best Regards.
    Attached Files Attached Files

+ 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. Date doesn't work properly with Filter
    By davidbelaev in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-19-2017, 07:01 PM
  2. Old excel file with picture insert macro doesn't work properly...
    By rcurious in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2014, 05:56 PM
  3. macro to copy cells to a new workbook doesn't work properly
    By dileva in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2013, 10:55 AM
  4. [SOLVED] Event macro runs in wrong workbook/doesn't work properly
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2012, 11:28 AM
  5. [SOLVED] Complicated Macro doesn't work properly if lines are deleted
    By BuzzOffSweetheart in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-11-2012, 01:32 PM
  6. Worksheet change event doesn't work properly
    By ffandango in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-05-2009, 06:03 PM
  7. Replies: 0
    Last Post: 02-10-2005, 02:46 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