|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 aroffice 于 2015-1-5 13:25 编辑
因需要写一个小程序要用到排名,数组是通过前面的程序计算出来的,在中间部分需要进行排名,然后应用排名继续计算
有没有办法解决在数组中直接进行排名。
附件是随机生成数据来模拟进行的,请各位大师指点!
数组排名.rar
(10 KB, 下载次数: 25)
Sub test()
temp = Sheet1.Range("A2:C51").Value
'对二维数组进行排名,不用写入工作表的方法
temp = szpm(temp, 2, 1, 3)
Sheet1.Range("D2:F51") = temp
End Sub
Private Function szpm(sz, fl As Integer, cj As Integer, mc As Integer)
Dim xbmin As Integer, xbmax As Integer, r1 As Integer, r2 As Integer
On Error Resume Next
r1 = UBound(sz, 2)
If Err.Number <> 0 Then Exit Function
On Error GoTo 0
rl = 0
xbmax = UBound(sz, 1)
xbmin = LBound(sz, 1)
If fl <= UBound(sz, 2) And fl >= LBound(sz, 2) And cj <= UBound(sz, 2) And cj >= LBound(sz, 2) And mc <= UBound(sz, 2) And mc >= LBound(sz, 2) Then
For r1 = xbmin To xbmax
sz(r1, mc) = 1
For r2 = xbmin To xbmax
If sz(r1, fl) = sz(r2, fl) And sz(r1, cj) < sz(r2, cj) Then sz(r1, mc) = sz(r1, mc) + 1
Next r2
Next r1
szpm = sz
End If
End Function
|
|