Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
alex.k
 
Posts: n/a
Default Custom function returning VALUE error


Hi,

I am trying to construct a simple function to calculate distance
between 2 points on Carthesian plane. The function I wrote:

Function FieldsXY(startx, starty, endx, endy)
FieldsXY = Application.SQRT((endx - startx) ^ 2 + (endy - starty)
^ 2)
End Function

The only result I'm getting is #VALUE! error. I tried to declare all
arguments as integer, didn't help. Help would be greatly appreciated,
as I'm no expert in this :).

regards,
Alex


--
alex.k
------------------------------------------------------------------------
alex.k's Profile: http://www.excelforum.com/member.php...o&userid=24637
View this thread: http://www.excelforum.com/showthread...hreadid=470598

  #2   Report Post  
Niek Otten
 
Posts: n/a
Default

Function FieldsXY(startx As Double, starty As Double, endx As Double, endy
As Double) As Double
FieldsXY = ((endx - startx) ^ 2 + (endy - starty) ^ 2) ^ (1 / 2)
End Function

--
Kind regards,

Niek Otten

Microsoft MVP - Excel

"alex.k" wrote in
message ...

Hi,

I am trying to construct a simple function to calculate distance
between 2 points on Carthesian plane. The function I wrote:

Function FieldsXY(startx, starty, endx, endy)
FieldsXY = Application.SQRT((endx - startx) ^ 2 + (endy - starty)
^ 2)
End Function

The only result I'm getting is #VALUE! error. I tried to declare all
arguments as integer, didn't help. Help would be greatly appreciated,
as I'm no expert in this :).

regards,
Alex


--
alex.k
------------------------------------------------------------------------
alex.k's Profile:
http://www.excelforum.com/member.php...o&userid=24637
View this thread: http://www.excelforum.com/showthread...hreadid=470598



  #3   Report Post  
Dana DeLouis
 
Posts: n/a
Default

Hi. Vba has its own Sqrt function, so SQRT wasn't included under
"Application.WorksheetFunction."

FieldsXY = Sqr((endx - startx) ^ 2 + (endy - starty) ^ 2)

HTH :)
--
Dana DeLouis
Win XP & Office 2003


"alex.k" wrote in
message ...

Hi,

I am trying to construct a simple function to calculate distance
between 2 points on Carthesian plane. The function I wrote:

Function FieldsXY(startx, starty, endx, endy)
FieldsXY = Application.SQRT((endx - startx) ^ 2 + (endy - starty)
^ 2)
End Function

The only result I'm getting is #VALUE! error. I tried to declare all
arguments as integer, didn't help. Help would be greatly appreciated,
as I'm no expert in this :).

regards,
Alex


--
alex.k
------------------------------------------------------------------------
alex.k's Profile:
http://www.excelforum.com/member.php...o&userid=24637
View this thread: http://www.excelforum.com/showthread...hreadid=470598



  #4   Report Post  
MrShorty
 
Posts: n/a
Default


Also make sure you've placed the function in an actual code module, and
not in the code page associated with a worksheet.


--
MrShorty
------------------------------------------------------------------------
MrShorty's Profile: http://www.excelforum.com/member.php...o&userid=22181
View this thread: http://www.excelforum.com/showthread...hreadid=470598

  #5   Report Post  
alex.k
 
Posts: n/a
Default


Thank you. Stupid me, I knew it is something simple. I actually spend
some time looking through help to find out if VB has a SQR function,
but didn't find it so I assumed it doesn't.
And maybe I should refresh my maths, as SQR is not even needed here [as
2nd answer shows:)]

Thank you both again.
Alex


--
alex.k
------------------------------------------------------------------------
alex.k's Profile: http://www.excelforum.com/member.php...o&userid=24637
View this thread: http://www.excelforum.com/showthread...hreadid=470598



  #6   Report Post  
Myrna Larson
 
Posts: n/a
Default

Hmmm... In Excel 2003, I typed 'square root' in the Help box; the first item
returned was the SQRT worksheet function.

On Mon, 26 Sep 2005 13:03:31 -0500, alex.k
wrote:


Thank you. Stupid me, I knew it is something simple. I actually spend
some time looking through help to find out if VB has a SQR function,
but didn't find it so I assumed it doesn't.
And maybe I should refresh my maths, as SQR is not even needed here [as
2nd answer shows:)]

Thank you both again.
Alex

  #7   Report Post  
Dana DeLouis
 
Posts: n/a
Default

Hi Alex. Here is a technique if interested. You typed "Application.SQRT"
....

FieldsXY = Application.SQRT((endx - startx) ^ 2 + (endy - starty)


Don't know what version you have, but in the latest versions of Excel, I
find it slightly better to use "WorksheetFunction" instead of just
"Application"
In the vba editor, go to Tools | Options | Editor tab, and make sure you
turn on "Auto List Members"
When you type "WorksheetFunction" followed by a period, you will see a list
of valid worksheet functions that are available. Older versions of Excel
required you to type "Application.WorksheetFunction" then period to get the
Auto List Members to show the functions.
HTH :)
--
Dana DeLouis
Win XP & Office 2003


"alex.k" wrote in
message ...

Thank you. Stupid me, I knew it is something simple. I actually spend
some time looking through help to find out if VB has a SQR function,
but didn't find it so I assumed it doesn't.
And maybe I should refresh my maths, as SQR is not even needed here [as
2nd answer shows:)]

Thank you both again.
Alex


--
alex.k
------------------------------------------------------------------------
alex.k's Profile:
http://www.excelforum.com/member.php...o&userid=24637
View this thread: http://www.excelforum.com/showthread...hreadid=470598



Reply
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
Custom Function Call Bill Martin -- (Remove NOSPAM from address) Excel Discussion (Misc queries) 5 September 6th 05 06:14 PM
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Excel Worksheet Functions 13 July 31st 05 03:59 PM
Why do I get a #Name error when I use the DateDif function? PhilS Excel Worksheet Functions 9 April 5th 05 04:51 PM
Why do I get a #Name error when I use the DateDif function? PhilS Excel Worksheet Functions 6 April 2nd 05 02:07 PM
Problem with VBA returning the contents of a long formula. [email protected] Excel Discussion (Misc queries) 2 February 23rd 05 12:14 AM


All times are GMT +1. The time now is 09:40 AM.

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

About Us

"It's about Microsoft Excel"