Macro for Multiple Sorts
Hi, this code works as long as all the columns has at least one data.
Sub Ordena()
Dim RangeToSort As Range
Dim NewStCell As Range
Dim MyColumn As Integer
MyColumn = 2
Set RangeToSort = Range(Cells(1, 1), Cells(1, 1).End(xlDown)) _
.Range("A1:G8")
RangeToSort.Sort Key1:=Range("B" & MyColumn), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
For MyColumn = 2 To 5
If Cells(1, MyColumn).End(xlDown).Offset(1, 0) = "" Then
Set NewStCell = Cells(1, MyColumn).End(xlDown). _
Offset(1, -MyColumn + 1)
Else
Set NewStCell = Cells(1, MyColumn).End(xlDown)._
End(xlDown).Offset(1, -MyColumn + 1)
End If
Set RangeToSort = Range(NewStCell, _
Cells(NewStCell.End(xlDown).Row, 7))
RangeToSort.Sort Key1:=Cells(1, MyColumn + 1), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Next MyColumn
End Sub
Hope this Helps.
Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.
|