View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default VBA - Passing a FUNCTION as an Argument

James,

You can't pass function pointers in VBA. The closest you can get
is to pass the name of the procedure as an string and use
Application.Run to run the procedure. E.g.,

Function DerFunction(F As String, Point1,Point2)
DerFunction = Application.Run(F)
End Function

DerFunction "TheFunctionName", 1, 2


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"James B" wrote in message
...
Some expert help is required on this one. I want to
create a VBA function that calculates the derivative of
another function between two points.

The syntax would be something like the following:

Gradient = DerFun(Height(), x1, x2)

where

Function DerFun(Arg_Function as function, point1, point2)
DerFun=(Arg_Function(point2)-ArgFunction(point1))/ _
(point2-point1)
End Function

What is the proper syntax, instead of "Arg_Function as
Function"?