andrewb90
Well-known Member
- Joined
- Dec 16, 2009
- Messages
- 1,077
Hello All,
I used the macro recorder to sort a range automatically and it seemed to work when I recorded it, but now I get an error, I was hoping someone could help me figure out why
thanks,
Andrew
I used the macro recorder to sort a range automatically and it seemed to work when I recorded it, but now I get an error, I was hoping someone could help me figure out why
Code:
Sub range() range("B5:V341").Select
ActiveWorkbook.Worksheets("Shed").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Shed").Sort.SortFields.Add Key:=range("B5:B341"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Shed").Sort.SortFields.Add Key:=range("D5:D341"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Shed").Sort.SortFields.Add Key:=range("C5:C341"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Shed").Sort
.SetRange range("B5:V341")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
thanks,
Andrew