+ Reply to Thread
Results 1 to 12 of 12

Date Format "d-mmm-yy" as Worksheet Name does not sort properly

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

    Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Hello,

    I'm pulling rows of data from a data worksheet where column 'B' contains random dates. All dates fall on the same day of the week. New worksheets are created for every new date encountered from column 'B' and the worksheet is given the name of the date in the format "d-mmm-yy", for example 1-Dec-13. The appropriate row is cut from the the data worksheet and pasted in the worksheet with the same date.

    This all works well but I have a sorting issue. I found the following worksheet sorting VBA code from Microsoft's site:

    Please Login or Register  to view this content.
    Things work well except the date format I'm working with does not sort properly. For example if worksheets are named '1-Dec-13', '8-Dec-13', '15-Dec-13', it sorts in the order of the initial digits without respecting the actual date.

    In this case the sort order result would be '1-Dec-13', '15-Dec-13', '8-Dec-13'.

    I put in some more random dates to see how it behaves and this is the sort order result:

    1-Dec-13, 15-Dec-13, 16-Apr-13, 3-Apr-13, 6-Jun-13, 8-Dec-13

    So is it handing these names as strings not dates since the month order is being messed up too? However the date variable has been declared as 'Date' and trying to force the specified format.

    The option of changing the date format is not available.

    Here is my code:
    Please Login or Register  to view this content.
    Thank you,

    TV
    Last edited by tv69; 12-12-2013 at 03:50 PM.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Untested. But it should sort all dates in one month? Will there be sheet names for multiple months?
    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Obviously a Worksheet object's Name value is a string. Run a macro to rename the sheet's to their numeric value, sort, and then run another or loop to rename your sheets using Format().

    e.g.
    Please Login or Register  to view this content.

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

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Hi Solus, the dates will span over at least a couple of years. The sort behaviour should be as it is when sorting dates in any excel column in ascending or descending order.

    Thanks,

    TV

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Rename the Sheets to yyyy-mm-dd format, use your sorting routine, then rename the sheets back to their original names.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Okay. My code only accounted for the single month you included in your original post. Ammended:
    Please Login or Register  to view this content.
    Last edited by Solus Rankin; 12-12-2013 at 04:31 PM.

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

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Solus,

    It errors out here with type mismatch.
    Please Login or Register  to view this content.
    and here:
    Please Login or Register  to view this content.
    It's currently not sorting correctly either.

    TV


    Quote Originally Posted by Solus Rankin View Post
    Okay. My code only accounted for the single month you included in your original post. Ammended:
    Please Login or Register  to view this content.

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

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Thank you Ken. I love the workarounds like that to get the desired result.

    TV



    Quote Originally Posted by Kenneth Hobson View Post
    Obviously a Worksheet object's Name value is a string. Run a macro to rename the sheet's to their numeric value, sort, and then run another or loop to rename your sheets using Format().

    e.g.
    Please Login or Register  to view this content.

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

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    Thank you LJ,

    This method is proving to be common!

    TV


    Quote Originally Posted by LJMetzger View Post
    Rename the Sheets to yyyy-mm-dd format, use your sorting routine, then rename the sheets back to their original names.

    Please Login or Register  to view this content.

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

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    My error, I have a sheet in the workbook named incoming!

    It sorts just fine without that sheet.

    Thanks,

    TV


    Quote Originally Posted by tv69 View Post
    Solus,

    It errors out here with type mismatch.
    Please Login or Register  to view this content.
    and here:
    Please Login or Register  to view this content.
    It's currently not sorting correctly either.

    TV

  11. #11
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    So is your initial issue solved?

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

    Re: Date Format "d-mmm-yy" as Worksheet Name does not sort properly

    It is solved I will mark the thread.

    Thanks Solus.

+ 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 of just "st" "nd" "rd" and "th" with text included
    By notrandom in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-10-2013, 05:45 PM
  2. Format(date,"mm/dd") returns date formatted as "mm-dd"
    By MenacingBanjo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2013, 09:15 AM
  3. Return "green", "yellow" or "red" from date/age and priority ranking
    By Cantaloop in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-04-2013, 12:12 AM
  4. Replies: 0
    Last Post: 06-11-2012, 07:44 PM
  5. Custom date format shows "051117.Thu" for today. Way to have "051117.Th", instead?
    By StargateFan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-17-2005, 06:25 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