office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

微信交流群(請(qǐng)用微信掃碼)

        

Access vba自定義求標(biāo)準(zhǔn)差函數(shù)MyStdevp(同樣適用于Excel VBA, VB6)

2020-04-16 08:00:00
zstmtony
原創(chuàng)
6023

Access自帶了DStdevp 聚合函數(shù)求標(biāo)準(zhǔn)差,但只能對(duì)表中字段求標(biāo)準(zhǔn)差,無法對(duì)提供的多個(gè)數(shù)字參數(shù)求標(biāo)準(zhǔn)差

所以自己做了一個(gè)求標(biāo)準(zhǔn)差的自定義函數(shù),同樣適用于Access VBA, Excel VBA, VB6


'MyStdevp 求標(biāo)準(zhǔn)差

Public Function MyStdevp(Optional dblNum1 As Variant, Optional dblNum2 As Variant, Optional dblNum3 As Variant, Optional dblNum4 As Variant, Optional dblNum5 As Variant)

Dim rs As Object
Dim dblAvg As Double
Dim dblSum As Double
Dim i As Integer
dblAvg = MyAvg(dblNum1, dblNum2, dblNum3, dblNum4, dblNum5)
If Not IsMissing(dblNum1) Then
i = i + 1
dblSum = dblSum + (dblNum1 - dblAvg) ^ 2

End If

If Not IsMissing(dblNum2) Then
i = i + 1
dblSum = dblSum + (dblNum2 - dblAvg) ^ 2

End If

If Not IsMissing(dblNum3) Then
i = i + 1
dblSum = dblSum + (dblNum3 - dblAvg) ^ 2

End If


If Not IsMissing(dblNum4) Then
i = i + 1
dblSum = dblSum + (dblNum4 - dblAvg) ^ 2

End If


If Not IsMissing(dblNum5) Then
i = i + 1
dblSum = dblSum + (dblNum5 - dblAvg) * (dblNum5 - dblAvg)

End If

If i > 0 Then
MyStdevp = Sqr(dblSum / i)
Else
MyStdevp = 0
End If


End Function


標(biāo)準(zhǔn)差的算法


    分享
    文章分類
    聯(lián)系我們
    聯(lián)系人: 王先生
    Email: 18449932@qq.com
    QQ: 18449932
    微博: officecn01
    移動(dòng)訪問