Simple custom function

R

Ryan

I am trying to program a custom function to make some simple math simpler.
Unfortunately this is my first swing at a custom function or VBA for that
matter. I would like to be able to pass 6 variables to a function and have it
do the following math:

CrossP(A1, A2, A3, B1, B2, B3)
CrossP = ((A2 * B3 - A3 * B2) ^ 2 + (A1 * B3 - A3 * B1) ^ 2 + (A1 * B2 - A2
- B1) ^ 2) ^ 0.5

Any thoughts?
 
P

Patrick Molloy

function CrossP(A1 as double, A2 as double, A3 as double, B1 as double, B2 as
double, B3 as double) as double
CrossP = ((A2 * B3 - A3 * B2) ^ 2 + (A1 * B3 - A3 * B1) ^ 2 + (A1 * B2 - A2
- B1) ^ 2) ^ 0.5
End Function
 
R

Ryan

I am still getting a #name error, this is exactly what I have in the VBA
editor;

Function CrossP(A1 As Double, A2 As Double, A3 As Double, B1 As Double, B2
As Double, B3 As Double) As Double

CrossP = ((A2 * B3 - A3 * B2) ^ 2 + (A1 * B3 - A3 * B1) ^ 2 + (A1 * B2 -
A2 - B1) ^ 2) ^ 0.5

End Function
 
P

Patrick Molloy

apologies ... I've been away. However, your code works fine for me.....



Option Explicit

Sub test()

Debug.Print CrossP(1, 2, 3, 4, 5, 6) ' 6.78232998312527

End Sub

Function CrossP(A1 As Double, A2 As Double, A3 As Double, B1 As Double, B2
As Double, B3 As Double) As Double

CrossP = ((A2 * B3 - A3 * B2) ^ 2 + (A1 * B3 - A3 * B1) ^ 2 + (A1 * B2 -
A2 - B1) ^ 2) ^ 0.5

End Function
 

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