- 论坛徽章:
- 0
|
插入一个模块,粘贴上这个函数,然后直接在表格里使用函数就可以了:- Public Function xxx1(rng As Range)
- Dim d1 As Object, a#, b#, result#
- Set d1 = CreateObject("Scripting.dictionary")
- For Each i In rng
- If Not d1.exists(Application.Rank(i, rng, 0)) Then _
- d1.Add Application.Rank(i, rng, 0), i
- Next i
- a = Abs((d1(1) - d1(2))) / d1(2): b = Abs((d1(3) - d1(2))) / d1(2) '未明白“超过15%”是指什么,请自行在这里定义
- If (a > 0.15 And b <= 0.15) Or (b > 0.15 And a <= 0.15) Then
- result = Application.Round(d1(2), 1)
- ElseIf (a > 0.15 And b > 0.15) Then
- result = 0
- End If
- Set d1 = Nothing
- xxx1 = result
- End Function
复制代码 精确度自行设置单元格格式就可以了
请参考
~ |
|