Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default Distance between cells

If the cells in a workshset are square (say 1 cm width and height) what is
the easiest way to calculate the distance between the center of one cell and
the center of another?
--
Gary's Student
  #2   Report Post  
Posted to microsoft.public.excel.misc
Niek Otten
 
Posts: n/a
Default Distance between cells

Use Pythagoras: a^2+b^2 = c^2, where a and b are the distances in rows and
columns

--
Kind regards,

Niek Otten

"Gary''s Student" wrote in message
...
If the cells in a workshset are square (say 1 cm width and height) what is
the easiest way to calculate the distance between the center of one cell
and
the center of another?
--
Gary's Student



  #3   Report Post  
Posted to microsoft.public.excel.misc
Ken Johnson
 
Posts: n/a
Default Distance between cells

Hi Gary's Student,
the following gave me an accurate result for the straight distance
between the centres of A1 and G7:

Public Sub Line_Length()
Dim Rng1 As Range, Rng2 As Range, c As Single, Side As Single
Set Rng1 = ActiveSheet.Range("A1")
Set Rng2 = ActiveSheet.Range("G7")
Side = Rng1.Height
c = Sqr(((Rng1.Row - Rng2.Row) * Side) ^ 2 + ((Rng1.Column -
Rng2.Column) * Side) ^ 2)
MsgBox c
End Sub

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default Distance between cells

Niek & Ken:
Thank you both.
--
Gary's Student


"Ken Johnson" wrote:

Hi Gary's Student,
the following gave me an accurate result for the straight distance
between the centres of A1 and G7:

Public Sub Line_Length()
Dim Rng1 As Range, Rng2 As Range, c As Single, Side As Single
Set Rng1 = ActiveSheet.Range("A1")
Set Rng2 = ActiveSheet.Range("G7")
Side = Rng1.Height
c = Sqr(((Rng1.Row - Rng2.Row) * Side) ^ 2 + ((Rng1.Column -
Rng2.Column) * Side) ^ 2)
MsgBox c
End Sub

Ken Johnson


  #5   Report Post  
Posted to microsoft.public.excel.misc
L. Howard Kittle
 
Posts: n/a
Default Distance between cells

Hi Gary's Student,

I tried Ken's code and it gave me 108.1873. Is that centimeters or what? I
just tried it on a standard sheet, no cell resizing.

Curious as to what you are applying this to.

Regards,
Howard

"Gary''s Student" wrote in message
...
If the cells in a workshset are square (say 1 cm width and height) what is
the easiest way to calculate the distance between the center of one cell
and
the center of another?
--
Gary's Student





  #6   Report Post  
Posted to microsoft.public.excel.misc
Ken Johnson
 
Posts: n/a
Default Distance between cells

Hi L. Howard Kittle,
measurements are in points (72 points per inch)
Ken Johnson

  #7   Report Post  
Posted to microsoft.public.excel.misc
Ken Johnson
 
Posts: n/a
Default Distance between cells

Hi Howard,
The code does rely on all cells being square, otherwise value of c is
incorrect.
I too am a little curious as to Gary''s Student's application.
Ken Johnson

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
Deselect Cells while using ctrl Sloth Excel Discussion (Misc queries) 5 July 14th 05 10:58 PM
Condensing a list/range with blank cells to a new list/range without blanks KR Excel Worksheet Functions 4 July 5th 05 04:23 PM
Fill cells from non-adjacent cells Abes Excel Discussion (Misc queries) 2 March 25th 05 01:15 PM
Help adding text values Texas-DC_271 Excel Worksheet Functions 7 January 15th 05 11:14 PM
Convert data type of cells to Text,Number,Date and Time Kevin Excel Worksheet Functions 1 December 31st 04 12:57 PM


All times are GMT +1. The time now is 04:43 PM.

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"