Public Function jsVAR(b, _
Optional lmd As Double = 0.99, _
Optional sum As Long = 0) As Double
Dim n As Long, i As Long, j As Long, temp As Double, jg As Double
If IsObject(b) Then
n = b.Count
Else
n = UBound(b, 2) - LBound(b, 2) + 1
End If
Dim q() As Double
ReDim q(1 To n)
For i = 1 To n
q(i) = b(i, 1)
Next i
Dim tempq() As Double
ReDim tempq(1 To n)
For i = 1 To n
tempq(i) = lmd ^ (CDbl(n) - CDbl(i)) * (1# - lmd) / (1# - lmd ^ CDbl(n))
Next i
For i = 1 To n
For j = i + 1 To n
If q(i) > q(j) Then
temp = q(i)
q(i) = q(j)
q(j) = temp
temp = tempq(i)
tempq(i) = tempq(j)
tempq(j) = temp
End If
Next j
Next i
For i = 1 To n
sum = sum + tempq(i)
If (sum >= 0.05) Then
jg = q(i)
Exit For
End If
Next i
jsVAR = jg
End Function
求助 excel vba这个函数的结果总是0,参数b是一个单元格区域
答案:2 悬赏:80 手机版
解决时间 2021-01-28 18:22
- 提问者网友:孤凫
- 2021-01-28 09:19
最佳答案
- 五星知识达人网友:雾月
- 2021-01-28 10:01
你数组里,任意2个值的和大于0.05,产生jg得不到值,默认为0。你的数组原型是什么,给看看
全部回答
- 1楼网友:痴妹与他
- 2021-01-28 10:13
很大的可能性是你的单元格的数字是文本形式的数字
把 sumcolor = application.sum(icell) + sumcolor
改为 sumcolor = icell*1 + sumcolor
ps:
application.sum 本身就是一个合计一组数据的函数,而icell 包含的只是一个单元格的值,不需要用这个函数.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯