VBA中的(升降序)排名问题

 1 Sub 升序()
 2  
 3     all_rows = Sheets(1).Range("a65536").End(xlUp).Row
 4      
 5     With ActiveWorkbook.Worksheets(1)
 6         .Sort.SortFields.Clear
 7         .Sort.SortFields.Add Key:=.Range("a1"), SortOn:=xlSortOnValues, Order:=xlAscending
 8         .Sort.SetRange Range("a4:j" & all_rows)
 9         .Sort.Header = xlYes
10         .Sort.Apply
11      
12     End With
13      
14     Range("F4:F" & all_rows).ClearContents
15 
16 
17 End Sub
18 
19 
20 Sub 降序()
21     all_rows = Sheets(1).Range("a65536").End(xlUp).Row
22     With ActiveWorkbook.Worksheets(1)
23         .Sort.SortFields.Clear
24         .Sort.SortFields.Add Key:=Range("e1"), SortOn:=xlSortOnValues, Order:=xlDescending
25         .Sort.SetRange Range("a4:j" & all_rows)
26         .Sort.Header = xlYes
27         .Sort.Apply
28     End With
29 
30     Range("F4") = "=RANK(E4,$E$4:$E$" & all_rows & ")"
31     Range("F4").Select
32     Selection.AutoFill Destination:=Range("F4:F" & all_rows)
33 
34 End Sub
35 
36  

 

 

 

posted @ 2022-12-28 10:20  *感悟人生*  阅读(494)  评论(0编辑  收藏  举报