CookieMonster76
Board Regular
- Joined
- Apr 30, 2015
- Messages
- 195
Hi
I have the following which works
ActiveWorkbook.Worksheets("Analysis").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Analysis").Sort.SortFields.Add Key:=Range("H2:H" & Range("A" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Analysis").Sort
.SetRange Range("A1:I1404")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
The range which it needs to sort is not necessarily always rows 1 to 1404, so I have replaced the red text with
.SetRange Range("A1:I" & Range("A" & Rows.Count).End(xlUp).Row)
but this doesn't work.
Could someone correct me please?
Thanks
Paul
I have the following which works
ActiveWorkbook.Worksheets("Analysis").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Analysis").Sort.SortFields.Add Key:=Range("H2:H" & Range("A" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Analysis").Sort
.SetRange Range("A1:I1404")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
The range which it needs to sort is not necessarily always rows 1 to 1404, so I have replaced the red text with
.SetRange Range("A1:I" & Range("A" & Rows.Count).End(xlUp).Row)
but this doesn't work.
Could someone correct me please?
Thanks
Paul