Sub SORT()
'
' SORT Macro
'
'
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Add(Range("F5:F8"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0 _
, 0)
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Add Key:=Range("E5:E8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="TSL", _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Add Key:=Range("H5:H8"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").SORT
.SetRange Range("C4:H8")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Save
Application.WindowState = xlMinimized
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
End Sub
Sub SortMacro()
Dim xRange As Range
Dim StartRow As Integer
Dim EndRow As Integer
Set xRange = Selection
StartRow = xRange.Cells(1, 1).Row
EndRow = xRange.Rows + StartRow - 1
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Add(Range(Cells(StartRow, "F"), Cells(EndRow, "F")), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0 _
, 0)
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Add Key:=Range(Cells(StartRow, "E"), Cells(EndRow, "E")), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="TSL", _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").SORT.SortFields.Add Key:=Range(Cells(StartRow, "H"), Cells(EndRow, "H")), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").SORT
.SetRange Range(Cells(StartRow, "C"), Cells(EndRow, "H"))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Save
End Sub
Dim rng As Range
Set rng = Application.Intersect(Selection, Range("C2:H1048576")).EntireRow
If rng Is Nothing Then Exit Sub[/pre]
-----
2) Replace this line:
----
[code].SetRange Range("C4:H8")
----
by this:
-----
[code].SetRange rng