+ Reply to Thread
Results 1 to 4 of 4

Trying to force a date format 'd-mmm-yy', not working.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Trying to force a date format 'd-mmm-yy', not working.

    Hello,

    I have worksheets named by dates in the format 'd-mmm-yy', for example 5-Jan-14. In that worksheet there are rows of data with dates that are the same as the sheet name. It may happen that a row of data will have a date <> 5-Jan-14 and would need to be moved to a new worksheet with the correct date.

    I have written an algorithm for this but there is a weird problem with dates in the format 'd-mmm-yy' where the day consists of a single digit. It seems the date in the worksheet for the case above is being recognized as '05-Jan-14'.

    To try and debug, I'm copying the Sheetname to a couple of cells via:
    Range("C22") = Worksheets("5-Jan-14").name
    Range("C23") = Format(Worksheets("5-Jan-14").name, "d-mmm-yy")
    With the above:
    cell 'C22' = '05-Jan-14'
    cell 'C23' = '05-Jan-14'

    A 'right click', 'format cells...' on either of the results above shows a custom number format 'dd-mmm-yy', whereas prior to the results assigned the cell formats were 'General'.

    In addition, the dates found in the rows of data have a format of 'Date', '14-Mar-01', as shown in the format interface corresponding to 'd-mmm-yy'

    When a date from these rows is assigned to a variable 'myDate' defined as 'String' and I then do the following:
    Dim myDate As String
    myDate = Cells(3,3)
    Range("C25") = myDate
    Range("C26") = Format(myDate, "d-mmm-yy")
    With the above:
    cell 'C25' = '01/05/2014'
    cell 'C26' = '05-Jan-14'

    In both cases the format is not being forced as desired!

    What's going on? Any help is much appreciated.

    Thanks,

    TV

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Trying to force a date format 'd-mmm-yy', not working.

    Try this,


    Range("C26") = Format(cdate(myDate), "d-mmm-yy")
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Contributor
    Join Date
    11-28-2013
    Location
    Here
    MS-Off Ver
    Excel 2010
    Posts
    119

    Re: Trying to force a date format 'd-mmm-yy', not working.

    xlbiznes,

    Thanks for the reply but it did not change anything.

    TV

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Trying to force a date format 'd-mmm-yy', not working.

    In that case you need to change the Windows Regional Settings under the Control Panel.

    Set the short date to -> M/d/yyyy or any other format which has a single d.

+ 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 Format not working
    By joyhampton in forum Excel General
    Replies: 2
    Last Post: 08-13-2013, 01:36 AM
  2. Force macro to a date format. Used a userform instead
    By Philb1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-16-2011, 05:30 AM
  3. Date Format not working with equations
    By Maudise in forum Excel General
    Replies: 1
    Last Post: 08-11-2010, 06:03 PM
  4. Force cell date format
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2007, 04:07 PM
  5. [SOLVED] the date format is not working ,sort by date doesn't work.
    By Rosa Campos in forum Excel General
    Replies: 1
    Last Post: 09-12-2005, 06:05 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