Mark F
Well-known Member
- Joined
- Jun 7, 2002
- Messages
- 515
- Office Version
- 365
- Platform
- Windows
The code below, kindly provided / supported by others in the group identifies / selects a range of rows where the contents in Column C match
It will then sort those rows using the sort criteria included
What I would like to be able to do is to somehow modify the code so that each subsequent block of rows of the same value in column C are sorted
For example rows 10 to 19 have value 1 in column C, so the code selects this range and sorts
Next , row 20 to 34 have the value 2 in column C so the code will select that range and sort, and so on until the last row of the sheet
Could you please help with addition / modification of the code
Many Thanks
Mark
It will then sort those rows using the sort criteria included
What I would like to be able to do is to somehow modify the code so that each subsequent block of rows of the same value in column C are sorted
For example rows 10 to 19 have value 1 in column C, so the code selects this range and sorts
Next , row 20 to 34 have the value 2 in column C so the code will select that range and sort, and so on until the last row of the sheet
Could you please help with addition / modification of the code
Code:
Sub SortSubDeptAlphabetically2() 'ALPHABETICALLY
On Error Resume Next
Application.ScreenUpdating = False
Dim firstRow As Long
Dim lastRow As Long
Dim actCelRow As Long
Dim colCnumber As Long
actCelRow = ActiveCell.Row
colCnumber = Cells(actCelRow, 3)
firstRow = actCelRow
If firstRow < 9 Then firstRow = 9
While Not IsEmpty(Cells(firstRow, 3)) _
And Cells(firstRow, 3) = colCnumber
firstRow = firstRow - 1
Wend
lastRow = actCelRow
If lastRow <= 9 Then lastRow = 9
While Not IsEmpty(Cells(lastRow, 3)) _
And Cells(lastRow, 3) = colCnumber
lastRow = lastRow + 1
Wend
Range(Cells(firstRow + 1, 1), Cells(lastRow - 1, "AY")).Select
With Selection
.Sort Key1:=.Cells(firstRow, 7), Order1:=xlAscending, _
key2:=.Cells(firstRow, 24), order2:=xlAscending, Header:=xlNo, key3:=.Cells(firstRow, 8), order3:=xlAscending, Header:=xlNo
End With
Range("a7:bb7").Select
ActiveWindow.ScrollRow = firstRow - 7
Range("ab" & firstRow + 1).Select
Application.ScreenUpdating = True
End Sub
Many Thanks
Mark