Hello, I select consecutive rows on a sheet and run this code to sort A>Z for those selected rows but it only works correctly with 4 rows. I want to be able to select more or in some cases fewer than 4 rows to be sorted. The selected rows will always start as consecutive rows on the sheet. Thanks
Code:
Sub Sort()
ActiveWorkbook.Worksheets("EnterSheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("EnterSheet").Sort.SortFields.Add Key:=ActiveCell. _
Offset(0, 5).Range("A1:A4"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("EnterSheet").Sort
.SetRange ActiveCell.Range("A1:AK4")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I have added a sample attachment.It seems the range needs to be changed.