Logarithmic averaging preset function in excel - using ranges as input values

ε祈祈猫儿з 提交于 2020-01-16 23:41:13

问题


I need to add my own function for logarithmic averaging to excel but i'm not sure how to have a range of values as an input value or how to make count the number of values in a given range. I have a small amount of experience with programming.

The formula i usually use in excel and am looking to implement as a pre-set function is the following:

=10*LOG(SUM(10^('range of values'/10)/'number of values in the range'))

Can anyone help me out?


回答1:


You can try this, you may need to adjust to account for blank cells or non-text in the range

Function TestUDF(rngValues As Range) As Double

    Dim lSumofValues As Long
    Dim lCountofValues As Long
    Dim rngLoop As Range

    lSumofValues = 0
    lCountofValues = rngValues.Count 'Get count of values in items in range

'Add up the values in the range
    For Each rngLoop In rngValues
        lSumofValues = lSumofValues + rngLoop.Value
    Next
'Perform Calculation
    TestUDF = 10 * Log((10 ^ (lSumofValues / 10) / lCountofValues))

End Function

And then simply enter =TestUDF(A1:A18) in a cell to use it.



来源:https://stackoverflow.com/questions/23956551/logarithmic-averaging-preset-function-in-excel-using-ranges-as-input-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!