First post on SO, and would hardly consider myself a coder, so this is probably easy... I have been struggling with this code for a while, tt seems to work for all columns except F, which is populated with dates in the format mm/dd/yyyy. The code doesn't execute completely when it reaches column F with dates.
To get this code, I used excel macro recorder and personalized the ranges.
Sub Sorting()
'
' Sorting Macro
'
'
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Ambulatory Care").Sort.SortFields.Clear
Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
ActiveWorkbook.Worksheets("Ambulatory Care").Sort.SortFields.Add Key:=Range( _
"A5:A" & lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Ambulatory Care").Sort.SortFields.Add Key:=Range( _
"B5:B" & lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Ambulatory Care").Sort.SortFields.Add Key:=Range( _
"C5:C" & lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Ambulatory Care").Sort.SortFields.Add Key:=Range( _
"I5:I" & lastrow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Ambulatory Care").Sort.SortFields.Add Key:=Range( _
"F5:F & lastrow"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Ambulatory Care").Sort
.SetRange Range("A4:J798")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A4").Select
End Sub