Hello....
I have recorded a macro code as below.
Range("A5:B5").Select
Range(Selection, Selection.End(xlDown)).Offset(-1, 0).Select
ActiveWorkbook.Worksheets("Result").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Result").Sort.SortFields.Add2 Key:=Range("B6:B13"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Result").Sort
.SetRange Range("A5:B13")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
The problem is the range is until B13. I want to make it the same as the range that I selected (not including the last row) as the first 2 lines above.
The reason is that the list might become more or less in the future. I can't include the last row because it contains subtotal.
Please advise how to change the code (the one that I put in bold letter)
Thank you in advance.
I have recorded a macro code as below.
Range("A5:B5").Select
Range(Selection, Selection.End(xlDown)).Offset(-1, 0).Select
ActiveWorkbook.Worksheets("Result").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Result").Sort.SortFields.Add2 Key:=Range("B6:B13"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Result").Sort
.SetRange Range("A5:B13")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
The problem is the range is until B13. I want to make it the same as the range that I selected (not including the last row) as the first 2 lines above.
The reason is that the list might become more or less in the future. I can't include the last row because it contains subtotal.
Please advise how to change the code (the one that I put in bold letter)
Thank you in advance.