PDA

View Full Version : Solved: Sort Method Not Working!



Ischyros
12-30-2008, 04:10 PM
I havecontrol on a worksheet that presents the user with a userform allowing them to select how they would like to sort the information on the worksheet. For example I have several columns of information associated with projects like completion date, cost, engineer, contractor, etc.

When the click the button a user form appears where the select the information field to sort the list by....I am having a problem when it comes to sorting the projects by the date.

The problem is that when is sorts by the date it doesn't completely work. Specifically, it does not know what to do with blanks as they are randomly distributed down the rows and the dates end up not being sorted in ascending order at all.

When I do this manually it works just fine.......Any suggestions, code is below
:banghead: .

sub sort()
Worksheets("Project List").Range("A3:CL65536").Select
Selection.Sort Key1:=Range("X3"), Order1:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End Sub

Bob Phillips
12-30-2008, 06:03 PM
See if this is any better



Sub sort()
Dim LastgRow As Long
Dim rng As Range

With Worksheets("Project List")

LastRow = Cells(.Rows.Count, "A").End(xlUp).Row
Set rng = .Range("A3").Resize(LastRow - 2, 90)
rng.sort Key1:=.Range("X3"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End Sub

Ischyros
12-30-2008, 07:05 PM
That worked beautifully! Thanks so much!:thumb