mardi 30 mai 2023

What modifications are needed to my VBA user defined function to allow a range or comma separated variables as input?

How to allow a UDF to accept as input, a range or comma separated variables?

Say I have this user defined function:

Function logsum(rngValues As Range) As Double With Application.WorksheetFunction Dim lSumofValues As Double Dim lAntilog As Double Dim rngLoop As Range.Select

    lSumofValues = 0
    lAntilog = 0

'For loop - add the antilogs of the values in the range
    For Each rngLoop In rngValues
        lAntilog = .Power(10, 0.1 * rngLoop.Value)
        lSumofValues = lSumofValues + lAntilog
    Next

'Perform calculation - logarithmic sum
    logsum = 10 * .Log10(lSumofValues)
End With

End Function

This returns the logarithmicn sum of a selected range of cells.

I require it to also function on selected cells, the same way as the standard "=SUM()" excel function works.

I think this will be simple for someone with the know-how to solve. Please let me know how this is done.




Aucun commentaire:

Enregistrer un commentaire