customized function

R

ravi

I am trying to create a customized function.When ever I use cosh or sinh or
ln .. function within a formula I get a compile error. Sub or function not
defined.

sample code

Function tg(number)
tg = Cosh(number) + Sin(number)
End Function

I get no error when I use this code but with simple sin and cos

Function tg(number)
tg = Cos(number) + Sin(number)
End function

any ideas why this happens ?

Thanks in advance

ravi
 
T

Tom Ogilvy

cos and sin are legitimate functions in VBA (as well as Excel worksheet
functions - but used as you do, you are using the VBA versions). This is
not true of Cosh, Sinh or Ln. You can use

Worksheetfunction.Cosh, WorksheetFunction.Sinh and WorksheetFunction.Ln.

There is actually a function Log in VBA that is the same as the Excel
Worksheet function Ln. So you could use Log instead of LN.
 
C

CDICKENS

Try this:

Function tg(number)
tg = Excel.WorksheetFunction.Cosh(number) + Sin(number)
End Function


That worked for me. The runtime did not know where to find the Cosh
function.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top