Public Function PJS(Cellbegain As Range, Cellend As Range) As Single
Dim iMax, iMaxNow, iMin, iMinNow, iCount, iCountNow As Single
Dim rRange As Range
Set rRange = Range(Cellbegain, Cellend)
iCount = rRange.Count
iCountNow = 0
iMax = 0
iMin = 0
Do Until iCountNow >= iCount * 0.05
iMax = WorksheetFunction.Max(rRange)
iMin = WorksheetFunction.Min(rRange)
iCountNow = iCountNow + 1
iMaxNow = iMaxNow + iMax
iMinNow = iMinNow + iMin
Loop
PJS = (WorksheetFunction.Sum(rRange) - iMaxNow - iMinNow) / (iCount - iCountNow * 2)
End Function
试试看吧。水平有限,程序还有些不完善,没有错误判断,关键是我不知道你的详细想法,我也没有测试结果是否正确,但思路肯定不会有问题的。
还有使用的时候格式应和如下一样:psj("a1","a10")
a1是开始数据区域,a10是结束数据区域。别忘记加引号!
如果不满意可以去ooffice精英俱乐部论坛vba板块求助,里面高手如云而且热心。地址:要注意的是注册之后不能马上发帖。