I get a #value error for my UDF which I have agonised over for hours/days. The code is:
The X data is:![]()
Function deltam(X As Variant, Y As Variant) As Double '..of a single peak. Dim YTenth As Double, XTenth1 As Double, XTenth2 As Double, I As Long, Temp As Double If X.Count <> Y.Count Then deltam = "## Unequal Range Sizes##" Exit Function End If YTenth = WorksheetFunction.Max(Y) / 10 'peak thenth of height I = 0 Do I = I + 1 'seeking the pair of points Temp = Y(I) If Y(I) >= YTenth Then 'on the increasing branch XTenth1 = X(I) + ((YTenth - Y(I)) * (X(I + 1) - X(I))) / (Y(I + 1) - Y(I)) Exit Do End If Loop Do I = I + 1 'seeking the pair of points Temp = Y(I) If Y(I) <= YTenth Then 'on the decreasing branch XTenth2 = X(I) + ((YTenth - Y(I + 1)) * (X(I + 1) - X(I))) / (Y(I) - Y(I + 1)) Exit Do End If Loop deltam = XTenth2 - XTenth1 End Function
98
98.02
98.04
98.06
98.08
98.1
98.12
98.14
98.16
98.18
98.2
98.22
98.24
98.26
98.28
98.3
98.32
98.34
98.36
98.38
98.4
98.42
98.44
98.46
98.48
98.5
98.52
98.54
98.56
98.58
98.6
98.62
98.64
98.66
98.68
98.7
98.72
98.74
98.76
98.78
98.8
98.82
98.84
98.86
98.88
98.9
98.92
98.94
98.96
98.98
99
99.02
99.04
99.06
99.08
99.1
99.12
99.14
99.16
99.18
99.2
99.22
99.24
99.26
99.28
99.3
99.32
99.34
99.36
99.38
99.4
99.42
99.44
99.46
99.48
99.5
99.52
99.54
99.56
99.58
99.6
99.62
99.64
99.66
99.68
99.7
99.72
99.74
99.76
99.78
99.8
99.82
99.84
99.86
99.88
99.9
99.92
99.94
99.96
99.98
100
100.02
100.04
100.06
100.08
100.1
100.12
100.14
100.16
100.18
100.2
100.22
100.24
100.26
100.28
100.3
... and the Y data selected is:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
4
5
11
22
30
40
49
58
74
89
89
90
72
64
38
18
3
3
0
0
1
0
0
1
If anyone can help me understand why I keep getting this error I will be very grateful!!!
Thanks
Bookmarks