|
名次段统计代码
- Sub test1()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
- arr = .Range("a1").Resize(r, c)
- End With
- For j = 6 To UBound(arr, 2) - 1 Step 2
- d.RemoveAll
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- d(arr(i, j)) = d(arr(i, j)) + 1
- End If
- Next
- nn = 1
- kk = d.keys
- For k = 0 To UBound(kk)
- mm = Application.Large(kk, k + 1)
- ss = d(mm)
- d(mm) = nn
- nn = nn + ss
- Next
- For i = 2 To UBound(arr)
- If Len(arr(i, j)) <> 0 Then
- arr(i, j + 1) = d(arr(i, j))
- End If
- Next
- Next
- With Worksheets("名次段统计")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- .Range("b2").Resize(r - 1, c - 1).ClearContents
- brr = .Range("a1").Resize(r, c)
- ReDim fsd(1 To UBound(brr))
- fsd(1) = 1000
- m = 1
- For i = UBound(brr) To 2 Step -1
- m = m + 1
- fsd(m) = Val(brr(i, 1))
- Next
- For j = 2 To UBound(brr, 2)
- d1(CStr(brr(1, j))) = j
- Next
- For i = 2 To UBound(arr)
- If d1.exists(CStr(arr(i, 3))) Then
- n = d1(CStr(arr(i, 3)))
- m = Application.Match(arr(i, 7), fsd, -1)
- If Not IsError(m) Then
- m = UBound(fsd) - m + 2
- brr(m, n) = brr(m, n) + 1
- End If
- End If
- Next
- .Range("a1").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|