CookieMonster76
Board Regular
- Joined
- Apr 30, 2015
- Messages
- 195
Hi
Searching around, i have found this as an efficient way to sort some data:
Worksheets("Sheet5").Sort.SortFields.Clear
Range("A4:M" & Cells(Rows.Count, "A").End(xlUp).Row).Sort Key1:=Range("L4:L" & Cells(Rows.Count, "A").End(xlUp).Row), Order1:=xlAscending, Header:=xlYes
I have then performed another action on it, and then need to re-sort it, but this time based on the criteria of 2 columns.
The macro recorder (amended for the range) give me this:
ActiveWorkbook.Worksheets("Sheet5").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet5").Sort.SortFields.Add2 Key:=Range("B4:B" & Cells(Rows.Count, "A").End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet5").Sort.SortFields.Add2 Key:=Range("D4:D" & Cells(Rows.Count, "A").End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet5").Sort
.SetRange Range("A4:K" & Cells(Rows.Count, "A").End(xlUp).Row)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Is there a way to shrink it down in a similar fashion to the single column sort?
Thanks
Paul
Searching around, i have found this as an efficient way to sort some data:
Worksheets("Sheet5").Sort.SortFields.Clear
Range("A4:M" & Cells(Rows.Count, "A").End(xlUp).Row).Sort Key1:=Range("L4:L" & Cells(Rows.Count, "A").End(xlUp).Row), Order1:=xlAscending, Header:=xlYes
I have then performed another action on it, and then need to re-sort it, but this time based on the criteria of 2 columns.
The macro recorder (amended for the range) give me this:
ActiveWorkbook.Worksheets("Sheet5").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet5").Sort.SortFields.Add2 Key:=Range("B4:B" & Cells(Rows.Count, "A").End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet5").Sort.SortFields.Add2 Key:=Range("D4:D" & Cells(Rows.Count, "A").End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet5").Sort
.SetRange Range("A4:K" & Cells(Rows.Count, "A").End(xlUp).Row)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Is there a way to shrink it down in a similar fashion to the single column sort?
Thanks
Paul