|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
用单元格排序确实方便,所以就不用字典和代码了
- Sub Main()
- '// 中国式排名,排名数字不间断,同值同名
- With Sheet1
- r = .Cells(.Rows.Count, 1).End(3).Row
- .Range("d2:e" & r).ClearContents
- With .Range("a1:e" & r)
- ar = .Value
- For i = 1 To r
- ar(i, 5) = i
- Next
- .Value = ar
- .Sort .Cells(1, 1), xlAscending, .Cells(1, 2), , xlAscending, .Cells(1, 3), xlDescending, xlYes
- ar = .Value
- For i = 2 To r
- x = ar(i, 1) & "_" & ar(i, 2)
- If x = ar(i - 1, 1) & "_" & ar(i - 1, 2) Then
- If ar(i, 3) = ar(i - 1, 3) Then
- ar(i, 4) = ar(i - 1, 4)
- Else
- ar(i, 4) = ar(i - 1, 4) + 1
- End If
- Else
- ar(i, 4) = 1
- End If
- Next
- .Value = ar
- .Sort .Cells(1, 5), xlAscending, , , , , , xlYes
- End With
- End With
- End Sub
复制代码 |
|