• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to fix Date format in VBA

aksoni

New Member
I want to restrict to enter data in a specified date format(eg: mm/dd/yyyy). i can control the display of date format but when i change this date again by double clicking it, then date format automatically converted in system date format. (I want to fix this date format, means it should not be on system depend date format)


Pl reply on my id as well: aksoni84@gmail.com
 
Why? A date is a date is a date. As long as it is a valid date, what you see is just a presentation layer above the real value.
 
Aksoni,


Welcome to Chandoo_Org Forums...


You can get this done by checking the International Setting and then apply the desired format through VBA).


In your code you can check what is the current system default setting and change accordingly.


Code:
Dim lngDateFormatType as long

<p>lngDateFormatType = Application.International(xlDateOrder)

'Order of date elements:

'0 = month-day-year

'1 = day-month-year

'2 = year-month-day

The above variable will have 0, 1 or 2 depending on the System Date Settings... and you can then play with them to format as per your requirments.

HTH

~VijaySharma
 
Back
Top