How to replace the 4 individual cell selections in a UDF with 2 ranges and complete t

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jay1202
    New Member
    • Aug 2010
    • 1

    #1

    How to replace the 4 individual cell selections in a UDF with 2 ranges and complete t

    Hello,

    I've gotten good at nesting formulas to the point that I need to start using UDF's.

    Function Dist(XA As Double, YA As Double, XB As Double, YB As Double)
    Dist = Sqr((YA - YB) ^ 2 + (XA - XB) ^ 2)
    End Function


    I think the function would be improved by using

    Function Dist(PT1 As Range, PT2 As Range)

    PT1 would contain an X,Y coordinate with PT2 containing a second. The UDF would make this monster much easier to manage.

    =IF(BV15="","", IF(IF(SQRT(POWE R(AL$21-BT15,2)+POWER(A K$21-BS15,2))<SQRT(P OWER(AL$21-(BP15),2)+POWER (AK$21-BO15,2)),AL$22, AK$22)=AL$22,IF (SQRT((POWER((B L15-BP15),2)+POWER( BK15-BO15,2)))<SQRT( POWER(BL15-BR15,2)+POWER(( BK15-BQ15),2)),BU15, BS15),IF(SQRT(P OWER(BL15-BV15,2)+POWER(B K15-BU15,2))<SQRT(P OWER(BL15-BT15,2)+POWER(B K15-BS15,2)),BO15,B Q15)))

    Best Regards,

    Jay
Working...