I'm using VBA script + command button to sort a spreadsheet. Everything works except for the fact that it puts the blank rows on top of the data. Ideally, the blank rows would go to the bottom.
If one of you talented VBA programmers could help me modify the following code to put the blank rows below the data, I would be extremely grateful! Thx so much in advance. -Jason
Private Sub cmdSort_Click()
On Error GoTo Error_Handler
ActiveSheet.Unprotect
Range("D9:Y175").Select
Selection.Sort Key1:=Range("D9"), Order1:=xlAscending, Key2:=Range("E9") _
, Order2:=xlAscending, Key3:=Range("J9"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
Exit_Procedure:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "An error has occurred in this application." & Err & ", " & Error & vbCrLf & vbCrLf & _
"Please contact your technical support person and report the problem.", vbExclamation, "Error!"
Resume Exit_Procedure
End Sub
If one of you talented VBA programmers could help me modify the following code to put the blank rows below the data, I would be extremely grateful! Thx so much in advance. -Jason
Private Sub cmdSort_Click()
On Error GoTo Error_Handler
ActiveSheet.Unprotect
Range("D9:Y175").Select
Selection.Sort Key1:=Range("D9"), Order1:=xlAscending, Key2:=Range("E9") _
, Order2:=xlAscending, Key3:=Range("J9"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
Exit_Procedure:
On Error Resume Next
Exit Sub
Error_Handler:
MsgBox "An error has occurred in this application." & Err & ", " & Error & vbCrLf & vbCrLf & _
"Please contact your technical support person and report the problem.", vbExclamation, "Error!"
Resume Exit_Procedure
End Sub