![]() |
#1
|
|||
|
|||
![]()
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 Last edited by 14spar15; 05-26-2023 at 08:27 AM. Reason: Added sample attachment |
#2
|
||||
|
||||
![]()
try:
Code:
Sub Sort2() Set SortRng = Intersect(Selection.EntireRow, Columns("A:AK")) If Not SortRng Is Nothing Then SortRng.Sort Columns("F"), xlAscending, Header:=xlNo End Sub |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
14spar15 | Excel Programming | 2 | 05-18-2023 07:57 AM |
Collapse Rows When NOT Selected | sheridan60 | Excel | 1 | 11-30-2022 01:23 AM |
![]() |
14spar15 | Excel Programming | 8 | 11-19-2018 08:08 AM |
![]() |
FromF | Excel | 2 | 09-09-2014 02:30 AM |
Trying to autofilter 8-10 rows of numbers to sort in a group | Jack-P-Winner | Excel | 0 | 11-25-2013 10:55 PM |