excel分组排序后取前三行
发布网友
发布时间:2022-12-02 03:05
我来回答
共1个回答
热心网友
时间:2023-11-08 14:33
可使用如下VBA程序:
Private Sub CommandButton1_Click()
Columns("A:C").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, SortMethod:=xlPinYin, DataOption1:= _
xlSortNormal, DataOption2:=xlSortNormal
For i = Range("A65536").End(xlUp).Row To 1 Step -1
If Application.WorksheetFunction.CountIf(Range("A:A"), Range("A" & i).Value) > 3 Then
Rows(i).Delete
End If
Next i
End Sub