如何用VBA实现中国式排名
Excel应用 2009-07-12 00:04:08 阅读109 评论0 字号:大中小 订阅
ExcelHome论坛的网友fsydw问:
大师!!!!!!如何用VBA实现中国式排名(数组公式),详见附件。谢谢!!!!!!
大师!!!!!!如何用VBA实现中国式排名(数组公式),详见附件。谢谢!!!!!!
[ 本帖最后由 fsydw 于 2009-7-10 21:25 编辑 ]
———————————————————————————
“狼行天下”版主的回答:
Sub yyy()
Dim arr, i As Long, n As Long, d
With Sheets("统计表")
arr = .[a4].Resize(.[a65536].End(xlUp).Row - 3)
Sub yyy()
Dim arr, i As Long, n As Long, d
With Sheets("统计表")
arr = .[a4].Resize(.[a65536].End(xlUp).Row - 3)
For i = UBound(arr) To 1 Step -1
If arr(i, 1) <> d Then n = n + 1: d = arr(i, 1)
arr(i, 1) = n
Next
[k4].Resize(UBound(arr)) = arr
End With
End Sub
If arr(i, 1) <> d Then n = n + 1: d = arr(i, 1)
arr(i, 1) = n
Next
[k4].Resize(UBound(arr)) = arr
End With
End Sub
ldy版主的回答:
Sub ttttt()
Set dic = CreateObject("scripting.dictionary")
For i = 4 To 52
dic(Cells(i, 1).Value * 1) = 0
Next
For i = 0 To dic.Count - 1
Set dic = CreateObject("scripting.dictionary")
For i = 4 To 52
dic(Cells(i, 1).Value * 1) = 0
Next
For i = 0 To dic.Count - 1
dic((Application.Large(dic.Keys, i + 1))) = i + 1
Next
For i = 4 To 52
Cells(i, "L") = dic(Cells(i, 1) * 1)
Next
End Sub
Next
For i = 4 To 52
Cells(i, "L") = dic(Cells(i, 1) * 1)
Next
End Sub
杨成云的回答(在版主ldy的基础上修改成自定义函数)
ldy版主水平可见之高,高。resize函数vba
我在他的基础上,将其改为自定义函数,即中国式排名的自定义函数
'y是数据区域首行的位置(在工作表的第几行)
'x是数据区域末行的位置(在工作表的第几行)
'a是自定义函数公式所在的行
'b是数据区域所处的列位置(在工作表的第几列)
我在他的基础上,将其改为自定义函数,即中国式排名的自定义函数
'y是数据区域首行的位置(在工作表的第几行)
'x是数据区域末行的位置(在工作表的第几行)
'a是自定义函数公式所在的行
'b是数据区域所处的列位置(在工作表的第几列)
Function ZGrank(y As Integer, x As Integer, a As Integer, b As Integer)
Set dic = CreateObject("scripting.dictionary")
For i = y To x
dic(Cells(i, b) * 1) = ""
Next
For i = y - 1 To dic.Count - 1
dic((Application.Large(dic.Keys, i + 1))) = i + 1
Next
ZGrank = dic(Cells(a, b) * 1)
End Function
Set dic = CreateObject("scripting.dictionary")
For i = y To x
dic(Cells(i, b) * 1) = ""
Next
For i = y - 1 To dic.Count - 1
dic((Application.Large(dic.Keys, i + 1))) = i + 1
Next
ZGrank = dic(Cells(a, b) * 1)
End Function
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论