Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting a column with dates

Status
Not open for further replies.

kragster

Technical User
May 9, 2007
55
DK
Hi,
I am making a macro in excel to sort a column by dates. The dates have the following format dd/mm/yy. This is the code I use:
Code:
Sub SortByBestilt()
    Range("B10:O65536").Select
'Header to sort after    
Selection.Sort Key1:=Range("H10"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortDate
End Sub

Problem is it sorts the dates as numbers not dates. Can anyone help me out here?
 
Woops. This is the code

Code:
Sub SortByBestilt()

    Range("B10:O65536").Select
    Selection.Sort Key1:=Range("H10"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    Range("B10").Select
          
End Sub
 



hi,

"Problem is it sorts the dates as numbers not dates"

REAL Dates are NUMBERS and that's EXACTLY how they sort.

Why do Dates and Times seem to be so much trouble? faq68-5827

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top