View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vasant Nanavati Vasant Nanavati is offline
external usenet poster
 
Posts: 1,080
Default Calling of simple function in Excel 97

The function should be placed in a standard module in the workbook that you
want to use it in. If it is in another (open) workbook, you will have to
prefix the function name with the workbook name(e.g.,
=OtherBook.xls!CSR(NumberArg)).

You can't use the active cell as the argument because worksheet functions
cannot change cells; in addition, you would have a circular reference.

--

Vasant






"TomCee" wrote in message
om...
Hello:

I am interested in doing some simple programming in Excel 97. The
Help facility in Excel has plenty of examples of writing functions,
but does little to describe how to call a user-written function from a
spreadsheet.

For example:
I have defined a function such as:

Function CSR(NumberArg As Double) As Double
If NumberArg < 0 Then ' Evaluate argument.
Exit Function ' Exit to calling procedure.
Else
CSR = Sqr(NumberArg) ' Return square root.
End If
End Function

How do I call this from the worksheet? How do I refer to the Active
Cell?
(I've tried to call it by entering =CSRR() in a worksheet, but get a
#NAME error. I am not certain how to use the ActiveCell property to
refer to the passed value properly. I've tried it a number of ways
here to no avail.)

Where do I define this function in the the Visual Basic Editor?
(I've entered it in the General Declarations part of the workbook, and
it seems to 'compile' fine, but does not work!)

Thanks for your help,
Tom