Hi guys,
I have a custom function that wasn't written by me [partial code below], it
finds the standard deviation from a list of numbers. It works fine and is
only used in one sheet in the workbook.
The problem I have is that it is being called when I run another piece of
code, but I'm not calling it.
Ive tried making it private in its own module but that doesn't fix it.
I've got a workaround at the moment in that I've put the lines in the
function
If ActiveSheet.Name = "Standard Dev" Then
Exit Function
End If
This seems to work, however if I step through the code then this function
is still called but steps through the If statement the same number of times
as theres data in the Standard Dev worksheet.
I've checked for the accidental use of the same variable in both bits of
code but there is none.
Am i missing something simple here?
Ron
Private Function WPAM(data As Range, DatEntry As Long)
Dim C() As Double, k1 As Variant, DatNum As Long, info As Long
Dim i As Long, j As Long, temp As Double, result As Double
If ActiveSheet.Name = "Standard Dev" Then '**
Exit Function '** My workaround
End If '**
DatNum = 0
For Each k1 In data
DatNum = DatNum + 1
Next k1
ReDim C(1 To DatNum, 1 To 2)
For j = 1 To DatNum
C(j, 1) = data(j, 1)
C(j, 2) = 20
Next
For i = 1 To 2
temp = C(DatEntry, i)
C(DatEntry, i) = C(1, i)
C(1, i) = temp
Next
result = 0
If C(1, 1) > 0 Then
For i = 0 To 300
temp = 1
For j = 2 To DatNum
temp = temp * Application.WorksheetFunction.NormDist(i, C(j, 1), C(j, 2),
True)
Next
temp = temp * Application.WorksheetFunction.NormDist(i, C(1, 1), C(1, 2),
False)
result = result + temp
Next
WPAM = result
Else
WPAM = 100000000
End If
End Function
Bookmarks