+ Reply to Thread
Results 1 to 3 of 3

Excel is changing the date format when it shouldn't

Hybrid View

  1. #1
    Registered User
    Join Date
    12-29-2009
    Location
    Dubai, UAE
    MS-Off Ver
    Excel 2007
    Posts
    5

    Excel is changing the date format when it shouldn't

    I have a problem that's causing much frustration:

    - I set my OS' regional settings to English (US) but changed the short date format to the more sensible dd/mm/yyyy

    - I have columns in Excel that are formatted dd/mm/yy

    - When I use Cells(1, 3).Value = "01/02/03" where C is one such column, "02/01/03" appears!

    Why is Excel changing this? Why does it think I would use .Value = and specify the incorrect format. How can I solve this problem?

    Thanks
    -jt

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Excel is changing the date format when it shouldn't

    It's better to use:

    Cells(1, 3).Value2 = DateSerial(2003, 2, 1)
    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Excel is changing the date format when it shouldn't

    The problem comes because Excel is implicitly converting the string you are applying to a date and it does this according to our US Chums' practice of mm/dd/yy. Dom's given you one way (the best), another would be:

    Cells(1, 3).Value = DateValue("01/02/03")
    Richard Schollar
    Microsoft MVP - Excel

+ 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