代码如下。。。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
s = [{"f5","f6","f7","g6","g7","h6","h7","i6","i7"}]
Dim ss(1 To 30, 1 To 1)
For i = 1 To 30
ss(i, 1) = i
Next
For i = 1 To UBound(s)
If Range(s(i)).Address = Target.Address Then
If Target.Row = 6 Then
Cells(9, Target.Column).Resize(30).ClearContents
ElseIf Target.Row = 5 Then
[f9:i38,k9:n38].ClearContents
Else
Select Case Target.Column
Case 6
Set rng = Cells(8, "f").Resize(31, 9)
num = 2
Set rg = Cells(8, "f").Offset(, Target.Column - 1)
Call sort_1(rng, rg, num)
Cells(9, Target.Column).Resize(30) = ss
Case 7
Set rng = Cells(8, "f").Resize(31, 9)
num = 1
Set rg = Cells(8, "f").Offset(, Target.Column - 1)
Call sort_1(rng, rg, num)
Cells(9, Target.Column).Resize(30) = ss
Case 8
Set rng = Cells(8, "f").Resize(31, 9)
num = 2
Set rg = Cells(8, "f").Offset(, Target.Column - 1)
Call sort_1(rng, rg, num)
Cells(9, Target.Column).Resize(30) = ss
Case 9
Set rng = Cells(8, "f").Resize(31, 9)
num = 1
Set rg = Cells(8, "f").Offset(, Target.Column - 1)
Call sort_1(rng, rg, num)
Cells(9, Target.Column).Resize(30) = ss
End Select
End If
Exit For
End If
Next
End If
End Sub
Sub test()
Application.EnableEvents = True
End Sub
Sub sort_1(rng, rg, num)
rng.Sort key1:=rg, _
order1:=num, Header:=xlYes
End Sub
|