Ok I am trying to auto sort rows of data when ever a new entry is added. I want to sort it by date. This is the code I am currently using:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Set the target Range
Set rng = Range("K2:K20000")
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
ActiveSheet.UsedRange.Sort Key1:=Range("k1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
This works, it auto sorts every new entry by date, only problem is the order is messed up. Example is sorts like this:
6-Oct-05
6-Oct-05
6-Oct-05
6-Oct-05
13-Oct-05
13-Oct-05
13-Oct-05
13-Oct-05
12-Oct-05
12-Oct-05
12-Oct-05
7-Oct-05
7-Oct-05
5-Oct-05
5-Oct-05
4-Oct-05
3-Oct-05
Any way to sort it so that it goes 01Oct - 20-OCT without skipping? In this one it has the double digit dates in the middle. ANy ideas?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
' Only look at single cell changes
If Target.Count > 1 Then Exit Sub
' Set the target Range
Set rng = Range("K2:K20000")
' Only look at that range
If Intersect(Target, rng) Is Nothing Then Exit Sub
ActiveSheet.UsedRange.Sort Key1:=Range("k1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
This works, it auto sorts every new entry by date, only problem is the order is messed up. Example is sorts like this:
6-Oct-05
6-Oct-05
6-Oct-05
6-Oct-05
13-Oct-05
13-Oct-05
13-Oct-05
13-Oct-05
12-Oct-05
12-Oct-05
12-Oct-05
7-Oct-05
7-Oct-05
5-Oct-05
5-Oct-05
4-Oct-05
3-Oct-05
Any way to sort it so that it goes 01Oct - 20-OCT without skipping? In this one it has the double digit dates in the middle. ANy ideas?