UDF's

S

shane

I'm trying my hand in UDFs. In practice I created the following UDF in a
module

Function Area(Length As Double, Width As Double)
Area = Length * Width
End Function

Back in work book, I type =Area(A1,B1) in cell C1.

The result shown in the cell is 0. The result shown from the formula
dialogue box is 24. I have no idea what's going on. Any help is sppreciated.
 
×

מיכ×ל (מיקי) ×בידן

Try not to use reserved words.
Maybe something like:
 
J

Jim Thomlinson

I used your exact code in a standard code module and it worked like a charm.
So just to verify...

Your code is exactly as posted. No spelling mistakes or such. Do you use
Option Explicit at the top of your code module?
 
G

Gord Dibben

What do you have in A1 and B1?

Perhaps the numbers are actually Text?

Format to General then re-enter the numbers in A1 and B1


Gord Dibben MS Excel MVP
 
J

Jim Thomlinson

Interestingly enough I tried that and text or number makes no difference. It
works in either case. I assume that it is becuse he declared the arguments as
double causing XL to do an implicit conversion. If I enter text such as abcd
the function returns #Value instead of 0.
 

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