Private
Sub
Worksheet_SelectionChange(
ByVal
Target
As
Range)
Application.ScreenUpdating =
False
Application.EnableEvents =
False
If
Target.Column < 101
And
Target.Row = 1
Then
r = Cells(Rows.Count, 1).
End
(3).Row
If
InStr(Cells(Target.Row, Target.Column),
"▲"
) > 0
Then
Range(Cells(1, 1), Cells(r, 100)).
Select
ActiveWorkbook.Worksheets(
"Sheet1"
).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(
"Sheet1"
).Sort.SortFields.Add Key:=Range(Cells(2, Target.Column), Cells(r, Target.Column)), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With
ActiveWorkbook.Worksheets(
"Sheet1"
).Sort
.SetRange Range(Cells(1, 1), Cells(r, 100))
.Header = xlYes
.MatchCase =
False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End
With
Cells(Target.Row, Target.Column) = Replace(Cells(Target.Row, Target.Column),
"▲"
,
"▼"
)
Cells(2, Target.Column).
Select
Else
Range(Cells(1, 1), Cells(r, 100)).
Select
ActiveWorkbook.Worksheets(
"Sheet1"
).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(
"Sheet1"
).Sort.SortFields.Add Key:=Range(Cells(2, Target.Column), Cells(r, Target.Column)), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With
ActiveWorkbook.Worksheets(
"Sheet1"
).Sort
.SetRange Range(Cells(1, 1), Cells(r, 100))
.Header = xlYes
.MatchCase =
False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End
With
Cells(Target.Row, Target.Column) = Replace(Cells(Target.Row, Target.Column),
"▼"
,
"▲"
)
Cells(2, Target.Column).
Select
End
If
End
If
Application.EnableEvents =
True
Application.ScreenUpdating =
True
End
Sub