Hi Peter,
try something as follow:
Pass and return Variants: it enables you to pass an Excel range, an excel
array, a single value. It also enables you to return a worksheet error if
necessary. Manage the different scenario of parameter type within the
function. Also this way, the function should be re-evaluated once a dependant
range is the sheet is modified.
'-------------------------------------
Function Newton(Var1 As Variant, Var2 As Variant) as Variant
Dim v2 As Double
On Error GoTo Error_Handler
v2 = CDbl(Var2) '<-- if fails then not number --> error_handler
If TypeOf Var1 Is Excel.Range Then 'case var2 is excel range
' eg: =newton(A1:A10,10)
'code here
' newton=
ElseIf TypeName(Var1) = "Variant()" Then 'case var2 is array
' eg: =newton({1,2,3},3)
'code here
'newton=
Else 'try to convert into double
'eg =newton(2,4)
'code here
'newton=
End If
Exit Function
Error_Handler:
Newton = CVErr(xlErrValue)
End Function
'---------------------------------------
Regards,
Sebastien
"Peter M" wrote:
> I currently have the following, which of course breaks down once you hit the
> limit of 29 arguments in a user defined function:
>
> In the Worksheet:
> =Newton(B11,B12,B13,B14,B15,B16,B17,B18,B19,B20,B21,B22,B23,
> B24,B25,B26,B27,B28,B29,B30,B31,B32,B33,B34,B35,B36,B37,B38,
> B39,B38)
>
> In VB:
> Function Newton(P, n, F, A1, m1, A2, m2, A3, m3, A4,m4, A5,m5,A6, m6,
> A7, m7, A8, m8, A9, m9, A10,m10, A11, m11, A12, m12, A13, m13, iannual)
>
> To redesign, I have:
>
> In the Worksheet:
> =Newton(B11:B39,B8)
>
> In VB:
> Function Newton(.......?)
> ??
>
> Any help here to make this work is appreciated. I can't seem to ge this to
> work.
>
> --
> Thanks for any help
Bookmarks