LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Array as Argument in User-Defined Functions

"?B?TWFyayBTY2hyZWliZXI=?=" wrote...
I am trying to write a user-defined function that calculates a complex
function, based on a given set of coefficients. For simplicity, let's
say the equation is y=a + bx + cx^2. I would like to set up the user-
defined function so that the argument for the coefficients can be input
as a range. Thinking something like this:

Function Polynomial(Coefficients,X_value)
Polynomial=Coefficient(1,0) + Coefficient(2,0)*X_value + _
Coefficient(3,0)*X_value^2
End Function

...
The actual function is more complex, and contains some logic testing
requirements. So I am trying to avoid writing a function that requires 15
input arguments. Can you offer some insight into a classy method to
accomplish this?



Function foo(bar As Variant, x As Double) As Variant
Dim k As Long

On Error GoTo ErrorHandler

For k = 1 To NeededNumberOfArguments
foo = foo + bar(k) * x ^ (k - 1)
Next k

ErrorHandler:
If Err.Number < 0 Then foo = CVErr(xlErrValue)
Err.Clear

End Function

--
To top-post is human, to bottom-post and snip is sublime.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Defined Functions MoTrekker Excel Discussion (Misc queries) 2 November 8th 09 06:36 PM
User Defined Functions CH Excel Worksheet Functions 4 September 22nd 08 10:16 AM
User defined functions without using VBA. [email protected] Excel Worksheet Functions 0 June 13th 06 05:44 PM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM
User Defined Functions Tom Waters Excel Programming 1 July 21st 03 12:00 PM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"