Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Harry Hunter   on Jan 14 In MS Office Category.

  
Question Answered By: Aylin Kaya   on Jan 14

If I've understood correctly I think I can do this as a one liner:

Function distance(rng1 As Range, rng2 As Range)
distance = Evaluate("SQRT(SUM((" & rng1.Address _
& "-" & rng2.Address & ")^2))")
End Function

(the middle line there has a vba  continuation line in and should paste
across without editing)

This gives the same result as the formula in the spreadsheet
array-entered thus:

=SQRT(SUM((D5:F7-K14:M16)^2))

(Array-entered means holding the Ctrl and Shft keys while pressing the
Enter key to commit the formula.)

Which in turn gives the same result as doing it long hand.

At the moment, there are no checks to see that both ranges  are the
same size. Use the function  in a worksheet like so:

=distance(D5:F7,K14:M16)

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Distance Function Or get search suggestion and latest updates.


Tagged: