+ Reply to Thread
Results 1 to 3 of 3

VBA Date formatting issue

Hybrid View

  1. #1
    Registered User
    Join Date
    10-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    8

    VBA Date formatting issue

    Hi Guys

    I'm having a mare getting Excel to format a date correctly. I have a user form that pops up when the workbook is opened and the user picks a date. The text box value will always store the date in the correct format i.e. dd/mm/yyyy but when the date gets put into the sheet it gets reformatted to mm/dd/yyyy but only if dd < 12 - if dd > 12 then the date gets formatted correctly!!!!!. The only way I can get round this is to format the destination cell as text but this prevents me form using it in a calculation.

    extract of code:

    Range("M3").Activate
    ActiveCell.NumberFormat = "dd/mm/yyyy"
    Let Range("M3").Value = TextBox2.Value
    Help!!!!

  2. #2
    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: VBA Date formatting issue

    I don't have english version of excel handy, but probably problem is generated by conversion of value in a textbox (type text even if it looks like date) into a cell value. May be using explicit conversion would be enough:
    Range("M3").Value = cdate(TextBox2)
    or
    Range("M3").Value = DateValue(TextBox2)
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    10-23-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VBA Date formatting issue

    Thanks Kaper - that seems to have done the trick

+ 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] Date formatting issue
    By ebeardsw in forum Excel General
    Replies: 1
    Last Post: 02-19-2014, 12:46 PM
  2. date formatting issue
    By MP3265 in forum Excel General
    Replies: 6
    Last Post: 02-06-2013, 03:13 PM
  3. Date Formatting Issue
    By hey_ray in forum Excel General
    Replies: 3
    Last Post: 02-02-2012, 02:59 PM
  4. Another date formatting issue
    By machepap in forum Excel General
    Replies: 2
    Last Post: 11-22-2011, 11:14 AM
  5. Formatting Date Issue
    By monty4u1 in forum Excel General
    Replies: 3
    Last Post: 11-24-2009, 12:04 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