Replace a character from cells used in UDF

14 Views Asked by At

thanks all for assisting in my last code. Moving on from this, I need this logaveraging user defined function to not freak out when an asterix ("*") is in a cell that usually contains a number, for instance 70 *. I'm trying to replace the * with ("") within the loop function but am doing something wrong. Please see line 20. Any suggestions to solve this issue as welcome. Thanks in advance!

Function dbax() As Double With Application.WorksheetFunction Dim lSumofValues As Double Dim lCountofValues As Double Dim lAntilog As Double Dim rngLoop As Range

Dim rngFunction As Range Set rngFunction = Application.Caller

Dim rngValues As Range Set rngValues = rngFunction.Offset(, -8).Resize(, 8)

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

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

'Perform calculation - logarithmic average
    dbax = 10 * .Log10(lSumofValues / lCountofValues)
End With

Application.Volatile

End Function

0

There are 0 best solutions below