Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
drbob2000
 
Posts: n/a
Default How do I get Excel to tell me the angle of a line

I am trying to determine the angle of a line drawn in Excel; I need to acess
angles from digital photos...so I import the photo and draw a line on it....I
need to know the angle of the line.
  #2   Report Post  
Harlan Grove
 
Posts: n/a
Default How do I get Excel to tell me the angle of a line

drbob2000 wrote...
I am trying to determine the angle of a line drawn in Excel; I need to acess
angles from digital photos...so I import the photo and draw a line on it....I
need to know the angle of the line.


A single line on it's own has no angles, or at any point has two rays
that form a 180 degree angle. Do you mean relative to the horizontal?
If so, drawn lines have Height and Width properties relative to their
'top-left' endpoint. Pass them as arguments to the worksheet function
ATAN2 to get the angle in radians.

As an example, run this macro after selecting a drawn line.

Sub rfh()
Dim s As Shape

If TypeOf Selection Is Line Then
Set s = ActiveSheet.Shapes(Selection.Index)
Else
Exit Sub
End If

With Application.WorksheetFunction
MsgBox _
prompt:=.Atan2(s.Width, IIf(s.VerticalFlip, 1, -1) *
s.Height), _
Title:="Angle selected line forms to the horizontal (in
radians)"
End With
End Sub

  #3   Report Post  
drbob2000
 
Posts: n/a
Default How do I get Excel to tell me the angle of a line

I could not get the macro to run (I don't have much experience with
this)...there was a syntax error....How do I get the properties of the
line....and yes I am measuring the angle from the horrizontal.

"Harlan Grove" wrote:

drbob2000 wrote...
I am trying to determine the angle of a line drawn in Excel; I need to acess
angles from digital photos...so I import the photo and draw a line on it....I
need to know the angle of the line.


A single line on it's own has no angles, or at any point has two rays
that form a 180 degree angle. Do you mean relative to the horizontal?
If so, drawn lines have Height and Width properties relative to their
'top-left' endpoint. Pass them as arguments to the worksheet function
ATAN2 to get the angle in radians.

As an example, run this macro after selecting a drawn line.

Sub rfh()
Dim s As Shape

If TypeOf Selection Is Line Then
Set s = ActiveSheet.Shapes(Selection.Index)
Else
Exit Sub
End If

With Application.WorksheetFunction
MsgBox _
prompt:=.Atan2(s.Width, IIf(s.VerticalFlip, 1, -1) *
s.Height), _
Title:="Angle selected line forms to the horizontal (in
radians)"
End With
End Sub


  #4   Report Post  
Harlan Grove
 
Posts: n/a
Default How do I get Excel to tell me the angle of a line

drbob2000 wrote...
I could not get the macro to run (I don't have much experience with
this)...there was a syntax error....How do I get the properties of the
line....and yes I am measuring the angle from the horrizontal.

....

The problem may be line wrapping. First, use a general code module in
VBA. Press [Alt]+[F11] to switch to the VB Editor, then run the menu
command Insert Module. That'll bring up a new, blank general code
module. Then paste the following code into it.

Sub rfh()
Dim s As Shape

If TypeOf Selection Is Line Then
Set s = ActiveSheet.Shapes(Selection.Index)
Else
MsgBox Prompt:="No drawn line selected", Title:="ERROR"
Exit Sub
End If

With Application.WorksheetFunction
MsgBox _
Prompt:=.Atan2( _
s.Width, _
IIf(s.VerticalFlip, 1, -1) * s.Height), _
Title:="Angle of selected line to horizontal (radians)"
End With
End Sub

Also, you must select a drawn line before running this macro.
Otherwise, it'll display an error dialog then exit.

  #5   Report Post  
drbob2000
 
Posts: n/a
Default How do I get Excel to tell me the angle of a line

Thanks!!
That worked...now I just need to figure out how to draw a line and have the
degrees marked next to it in a field. (if you know how to do that it would
be wonderfull for you to share :) however, I do plan to attempt learning
much more about VB.

Thanks again.

"Harlan Grove" wrote:

drbob2000 wrote...
I could not get the macro to run (I don't have much experience with
this)...there was a syntax error....How do I get the properties of the
line....and yes I am measuring the angle from the horrizontal.

....

The problem may be line wrapping. First, use a general code module in
VBA. Press [Alt]+[F11] to switch to the VB Editor, then run the menu
command Insert Module. That'll bring up a new, blank general code
module. Then paste the following code into it.

Sub rfh()
Dim s As Shape

If TypeOf Selection Is Line Then
Set s = ActiveSheet.Shapes(Selection.Index)
Else
MsgBox Prompt:="No drawn line selected", Title:="ERROR"
Exit Sub
End If

With Application.WorksheetFunction
MsgBox _
Prompt:=.Atan2( _
s.Width, _
IIf(s.VerticalFlip, 1, -1) * s.Height), _
Title:="Angle of selected line to horizontal (radians)"
End With
End Sub

Also, you must select a drawn line before running this macro.
Otherwise, it'll display an error dialog then exit.


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
how to change line spacing for text box in excel chart Anne Charts and Charting in Excel 1 October 5th 05 12:11 AM
A 2 line text showing up in the Cell in Excel prints in 1 line Danny Excel Discussion (Misc queries) 6 July 12th 05 08:47 PM
Line chart in Excel - trendline incomplete [email protected] Charts and Charting in Excel 7 May 13th 05 01:21 PM
Can you have a vertical line graph in Excel 2003 smithers2002 Charts and Charting in Excel 3 January 12th 05 01:27 PM
How do I delete every other line in an Excel document with over 3. Darren Excel Discussion (Misc queries) 3 December 22nd 04 06:50 PM


All times are GMT +1. The time now is 07:52 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"