UDF to ignore an asterisk in a calculation without modifying the source data

15 views Asked by At

My UDF is working for the most part but I need help with one element. The function is working thus far do to the following: Takes the values in the 8 cells to left of where the function is called, adds a constant to them (aws) and returns the log average as per the relevant acoustic equation. I have a problem in ignoring asterisks "* " in cells that contain one. Currently I have managed to remove the "* " from the data (this section:

spectrum.Replace What:="~*", Replacement:="", LookAt:=xlPart, 
SearchOrder _
:=xlByColumns, MatchCase:=False, SearchFormat:=False, 
ReplaceFormat:=False)

but this is the issue.. I don't want to modify the raw data containing an asterisk for instance "54.5* " must stay as this in the raw data as the asterisk has significance! I simply want for the UDF to mathematically ignore the "* " for the purpose of the calculation. Help please!

Function dbax(Optional start)
aws = Array(-56.7, -39.4, -26.2, -16.1, -8.6, -3.2, 0, 1.2, 1, -1.1, -6.6)
ob = Array(16, 32, 63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000)

Dim rngFunction As Range
Set rngFunction = Application.Caller
    
Dim spectrum As Range
Set spectrum = rngFunction.Offset(, -8).Resize(, 8)

If IsMissing(start) Then
    x = 2
Else
    If start = 31.5 Then start = 32
    x = 0
    Do While start <> ob(x)
        x = x + 1
    Loop
End If
rc = spectrum.Rows.Count + spectrum.Columns.Count - 1
running = 0
For y = 1 To rc
    spectrum.Replace What:="~*", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByColumns, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
running = running + 10 ^ ((spectrum(y) + aws(y + x - 1)) / 10)
Next y
dbax = Application.Round((10 * Application.Log(running)), 1)
End Function
0

There are 0 answers