siv 发表于 2009-07-28 11:45

请帮弄条公式,EXCEL 感激!

请帮弄条公式,EXCEL 感激!
假设有三个值A1=35,B1=36 ,C1=37求其平均值 条件如下:


1、精确到0.1。
2、三个值的最大值或最小值中的一个与中间值的差值超过15%那么舍去最大值和最小值取中间值。
3、三个值的最大值和最小值与中间值的差值都超过15%那么该数组无效返回空白。 XCEL 感激!

shambhala 发表于 2010-03-07 19:01

插入一个模块,粘贴上这个函数,然后直接在表格里使用函数就可以了: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精确度自行设置单元格格式就可以了

请参考
~
页: [1]
查看完整版本: 请帮弄条公式,EXCEL 感激!