|
feipeng1 或许梦寐以求的效果 我只是用VBA去实现她
- Sub aSort()
- Dim r As Range, d As Object
- a = Cells(1, 1).End(xlDown).Row - 1
- ReDim jf(1 To a), fb(1 To a, 1 To 2), rr(1 To a, 1 To 2), tmp(1 To a)
- Set d = CreateObject("scripting.dictionary")
- For i = 1 To a
- Set r = Cells(i + 1, 2).Resize(1, a)
- f = 0: b0 = 0: b1 = 0
- For Each c In r
- If InStr(c, ":") Then
- v0 = Val(Split(c, ":")(0)): v1 = Val(Split(c, ":")(1))
- b0 = b0 + v0: b1 = b1 + v1
- If v0 > v1 Then
- f = f + 2
- ElseIf v0 < v1 Then
- f = f + 1
- End If
- End If
- Next
- jf(i) = f: fb(i, 2) = b0 / IIf(b1 = 0, 1, b1)
- If Not d.exists(f) Then d(f) = i Else d(f) = d(f) & " " & i
- Next
- k = d.keys: t = d.items
- For i = 0 To d.Count - 1
- it = Split(t(i))
- If UBound(it) > 0 Then
- For y = 0 To UBound(it)
- b0 = 0: b1 = 0
- For x = 0 To UBound(it)
- c = Cells(it(y) + 1, 1).Offset(0, it(x))
- If InStr(c, ":") Then
- b0 = b0 + Val(Split(c, ":")(0))
- b1 = b1 + Val(Split(c, ":")(1))
- End If
- Next
- fb(it(y), 1) = b0 / IIf(b1 = 0, 1, b1)
- Next
- End If
- Next
- For i = 1 To a
- tmp(i) = jf(i) * 10000 + fb(i, 1) * 1
- Next
- St = bSort(tmp, False)
- For i = 1 To a
- tmp(i) = St(i) * 10000 + fb(i, 2) * 1
- Next
- St = bSort(tmp, True)
- For i = 1 To a
- rr(i, 1) = jf(i)
- rr(i, 2) = St(i)
- Next
- Cells(2, a + 2).Resize(a, 2) = rr
- set r=nothing
- set d=nothing
- End Sub
- Private Function bSort(arry(), bl As Boolean)
- ub = UBound(arry)
- ReDim tmp(1 To ub), temp(1 To ub), t(1 To ub)
- For i = 1 To ub
- If bl = False Then
- tmp(i) = WorksheetFunction.Small(arry, i)
- Else
- tmp(i) = WorksheetFunction.Large(arry, i)
- End If
- temp(i) = i
- If i > 1 Then
- If tmp(i) = tmp(i - 1) Then temp(i) = temp(i - 1)
- End If
- Next
- For i = 1 To ub
- n = WorksheetFunction.Match(arry(i), tmp, 0)
- t(i) = temp(n)
- Next
- bSort = t
- End Function
- Private Sub Worksheet_Change(ByVal Target As Range)
- a = Cells(1, 1).End(xlDown).Row
- If Target.Row <= a And Target.Column <= a Then
- If InStr(Target, ":") Then
- Cells(Target.Column, Target.Row) = Split(Target, ":")(1) & ":" & Split(Target, ":")(0)
- Call aSort
- End If
- End If
- End Sub
复制代码
[ 本帖最后由 泓() 于 2010-7-29 14:08 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
|