Autosort problem

Hello, i didnt know that this forum exist. It looks like a good place to learn more about vba

I have a problem with autosort in excel, i want to order one table based on the date of one column,

Private Sub worksheet_change(ByVal target As Range)
On Error Resume Next
Range("D1").Sort Key1:=Range("D2"), _
Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlSortColumns

End Sub
That code works if i put the dates on the column but the thing is that column have the data based in other one that is on other sheet. When i put that code it doesnt work and looking in internet i saw this one:

Private Sub WorkSheet_Calculate()
Columns("D").Sort Key1:=Range("D2"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlSortColumns

End Sub

With that one everytime i put new data it goes in a run time error 1004, sort method of Range class failed
I tried everything i could think of but still the same thing

Other thing is that the column use dates so when i manual sort it it goes all the blanks one on the top is there any way to dont sort at all the blanks?

Thx in advance :P

Nick's picture

sorting data on one sheet by

sorting data on one sheet by data on another sheet ?!... Keep all your data together

When I sort, all blanks fall to the bottom whether it's ascending or descending by date. Maybe it's an Excel version issue.

To rectify, you'd need a helper column (an extra column with a formula based on the date column) where you replace the blank by something that goes to the bottom: "Blank" maybe... Then sort by the helper column