Sorting Dates
Sorting Dates
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Sorting Dates

  1. #1
    Guest

    Default

     
    Sorry, this has probably been beaten to death...

    I have a column set up as MM/DD/YY, and I need to be able to sort on the MM. All I can get it to do is sort on the YY.

  2. #2
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    In the next available column, write =month(a1), change the range to the approprite column with MM/DD/YY, and the same row. Copy the formula down, sort on the results and delete the contents of your new column.

    Cheers,

    Nate

    [ This Message was edited by: NateO on 2002-02-28 13:56 ]

  3. #3
    Guest

    Default

    can you say that again in different words? sorry, it didn't make sense to me.

  4. #4
    Guest

    Default

    ok, i figured it out...

    I did =month(C:C) in one column, and =day(B:B) in another column, and just sorted on those two columns. tx.

  5. #5
    Board Regular hennahairgel's Avatar
    Join Date
    Feb 2002
    Location
    Bristol, England
    Posts
    53
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    It's a bit clunky but it works. Excel stores dates as numbers; I cannot think of a way to sort on every 28/30/31's digit depending on day, so I have opted to split the date up and attack it from there.
    I've done my work with the dates in coulmn E. Adjust to suit.


    CODE:


    Sub sortbymonth()

    Range("e1").Select
    Range(ActiveCell, ActiveCell.End(xlDown)).Select
    noofrows = Selection.Rows.Count
    'insert the colums we need
    Columns("F:H").Select
    Selection.Insert Shift:=xlToRight
    'select the column with the dates in; this one column E
    Columns("E:E").Select
    'use the text to columns to split the data in columns, column 1 months, 2 day, 3 year
    Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
    :="/", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
    TrailingMinusNumbers:=True
    'format the first row in number format (it is still hung up in the date format)
    Columns("e:H").Select
    Selection.NumberFormat = "0"
    'selct the columns to sort
    Columns("E:I").Select
    'sort by column e, the month column, other data in column i. expand to contain...
    Selection.Sort Key1:=Range("E1"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    For i = 0 To (noofrows - 1)
    Monthval = Range("e1").Offset(i, 0).Value
    Dayval = Range("f1").Offset(i, 0).Value
    yearval = Range("g1").Offset(i, 0).Value
    Dateval = Monthval & "/" & Dayval & "/" & yearval

    Range("H1").Offset(i, 0).Formula = Dateval


    Next i

    'formats the cells properly
    Columns("H:H").Select
    Selection.NumberFormat = "m/d/yyyy"
    'delets the working columns
    Columns("E:G").Select
    Range("G1").Activate
    Selection.Delete Shift:=xlToLeft
    End Sub

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com