PDA

View Full Version : Autosort vba problem



seker
02-24-2015, 05:09 PM
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

Yongle
02-25-2015, 08:34 AM
What is the sheet name of the worksheet which holds the data?
What is the range for the data to be sorted? (A1 to Z999)
Will you be adding new rows of data?
Are you trying to sort based on date and are the dates in column D?
In which column are the blanks?
Yon