Auto Sort Problems

Slaymor

New Member
Joined
Sep 30, 2005
Messages
46
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?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top