PDA

View Full Version : [SOLVED] Sort each group in descending order



elketa1252
05-20-2017, 01:29 PM
So what i basically want is to sort these data independently from one another from highest to lowest. Columns A through F, sorted based on column F, group H to M sorted based on column M and so on, I would like the VBA not to have a limit because my data does not always end in the same column. Any help would be appreciated.

Thanks in advance.19234

Paul_Hossler
05-20-2017, 01:49 PM
Again, this is very similar to your other questions

You can integrate each of the small macros into a larger single one




Option Explicit
Sub SortData()
Dim i As Long, iLast As Long, j As Long
Dim r As Range

Application.ScreenUpdating = False

With Worksheets("Data")
iLast = .Cells(1, .Columns.Count).End(xlToLeft).Column

For i = 1 To iLast Step 5
Set r = .Cells(1, i).CurrentRegion

With .Sort
.SortFields.Clear
.SortFields.Add Key:=r.Columns(6), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange r
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Next i

End With
Application.ScreenUpdating = True
End Sub

rlv
05-20-2017, 06:12 PM
Sub SameQuestionAsInOtherThreadSort()
Dim R As Range, CellGroup As Range
Dim CollectionOfRanges As Areas

With ActiveSheet
Set CollectionOfRanges = Rows("1:" & .Rows.Count).SpecialCells(xlCellTypeConstants).Areas

For Each CellGroup In CollectionOfRanges
CellGroup.Sort Key1:=CellGroup.Range("A4"), Order1:=xlDescending
Next CellGroup
End With
End Sub

elketa1252
05-21-2017, 08:53 AM
Thanks guys, you guys made my weekend.

snb
05-21-2017, 09:37 AM
Sufficient code

Sub M_snb()
For Each it in activesheet.rows(1).specialcells(2).areas
it.currentregion.sort it.cells(1)
Next
End Sub