![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
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 |
|
Guest
Posts: n/a
|
can you say that again in different words? sorry, it didn't make sense to me.
|
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 |
|
New Member
Join Date: Feb 2002
Location: Bristol, England
Posts: 39
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|