|
Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("汇总表")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(2, Columns.Count).End(xlToLeft).Column
If r < 3 Or y < 2 Then MsgBox "汇总表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
With Sheets("统计表")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("b2:c" & rs) = Empty
br = .Range("a1:c" & rs)
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
d(Trim(br(i, 1))) = i
End If
Next i
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
xh = d(Trim(ar(i, 1)))
If xh <> "" Then
For j = 2 To y Step 1
If Trim(ar(i, j)) = 1 Then
br(xh, 2) = br(xh, 2) + 1
End If
Next j
End If
End If
Next i
.Range("a1:c" & rs) = br
For i = 2 To rs
.Cells(i, 3) = Application.Rank(.Cells(i, 2), .Range("b2:b" & rs)) '''排名
Next i
.Range("a1:c" & rs).Sort .[b1], 2, , , , , , 1 '第一个数据,表示升序还是降序,2为升序,1为降序,第二个数据表示标题行数
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|