|
EXCEL江湖 发表于 2014-8-10 21:04
谢谢香川群子多次帮助,我也要加强学习,争取也能象您一样帮助更多的人!
自定义数组函数
排名部分套用香川群子- Function swsx(rng)
- Dim fen(), ptj(), mc()
- arr = rng
- ms = UBound(arr, 1)
- ps = UBound(arr, 2)
- ReDim fen(1 To ms, 1 To 2)
- ReDim mc(1 To ms, 1 To 1)
- For i = 1 To ms
- ReDim ptj(1 To ms)
- For j = 1 To ps
- ptj(arr(i, j)) = ptj(arr(i, j)) + 1
- Next
- For j = 1 To ms
- If ptj(j) > 0 Then
- fen(i, 1) = fen(i, 1) + (2 ^ (ms - j)) * (2 ^ ptj(j))
- fen(i, 2) = i
- End If
- Next
- Next
- '下面是香川改进冒泡算法排序
- For i = 1 To ms
- s = fen(i, 1): t = fen(i, 2)
- For j = i + 1 To ms
- If fen(j, 1) > s Then s = fen(j, 1): t = fen(j, 2): r = j
- Next
-
- If r Then
- fen(r, 1) = fen(i, 1): fen(i, 1) = s
- fen(r, 2) = fen(i, 2): fen(i, 2) = t
- r = 0
- End If
- Next
- '排序完成后 重新整理得到正确的名次结果
- For i = 1 To ms
- mc(fen(i, 2), 1) = i
- Next
- swsx = mc
- End Function
复制代码 |
|