+ Reply to Thread
Results 1 to 4 of 4

Unable to format a date properly pulled from a cell

  1. #1
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Unable to format a date properly pulled from a cell

    Hello,

    In cell B5 of sheet1 contains a date which changes everytime when i open excel file. The date is in the M/D/YYYY format.

    I am using the following code to use that date in MM/DD/YYYY format.

    Please Login or Register  to view this content.
    If cell B5 of sheet1 is 2/1/2014, but my code is resulting in wrong as 01/02/2014.

    How to fix this?

  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,623

    Re: Unable to format a date properly pulled from a cell

    check first if the date in B5 is really Jan 2nd.
    May be try:
    Please Login or Register  to view this content.
    Last edited by Kaper; 02-26-2014 at 12:46 PM. Reason: Whoops, I missed code tags.
    Best Regards,

    Kaper

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Unable to format a date properly pulled from a cell

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    02-11-2014
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Unable to format a date properly pulled from a cell

    Quote Originally Posted by laxminarayana View Post
    Hello,

    In cell B5 of sheet1 contains a date which changes everytime when i open excel file. The date is in the M/D/YYYY format.

    I am using the following code to use that date in MM/DD/YYYY format.

    Please Login or Register  to view this content.
    If cell B5 of sheet1 is 2/1/2014, but my code is resulting in wrong as 01/02/2014.

    How to fix this?
    The numberformat "M/D/YYYY" is a special format that will give the default date format corresponding to the date format defined by the ControlPanel in Windows. Which in your country is "DD/MM/YYYY"

    So that is the format you should use in your code:
    Please Login or Register  to view this content.
    If you want your Workbook to be exported in other countries like USA, better is to use

    Please Login or Register  to view this content.
    as suggested by Norie.

    Cheers

    Docmarti
    Last edited by Docmarti; 02-26-2014 at 02:42 PM.

+ 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. How to format a date pulled from a cell?
    By laxminarayana in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 11:19 PM
  2. [SOLVED] Unable to Format Date after using Text to Columns
    By tropsog in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-31-2013, 11:22 AM
  3. [SOLVED] Unable to format cells into date format
    By katieshields in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-28-2013, 05:08 AM
  4. Unable to change date format
    By hafeezcloud in forum Excel General
    Replies: 3
    Last Post: 09-16-2012, 07:18 AM
  5. [SOLVED] Unable to format date
    By DLProcessor in forum Excel General
    Replies: 4
    Last Post: 09-13-2012, 02:19 PM

Tags for this Thread

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