• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 65
  • Last Modified:

How do I change the angles of an existing triangle by entering different values in 3 cells?

That's pretty much it. I know I can move the apex of a triangle with this code, the position of the apex determined by the value in [O2] with this code:
ActiveSheet.Shapes.Range(Array("My Triangle")).Adjustments.Item(1) = [O2]

Open in new window

But I would like some code that keeps the apex at zero and sets the apex angle to 60 degrees.

How do I write that?

Thanks!
John
0
John Carney
Asked:
John Carney
  • 2
1 Solution
 
Martin LissOlder than dirtCommented:
Excel isn't a drawing program so I believe the answer is that you can't do it with Excel's triangle shapes since the right triangle shape always has to have one angle of 90 degrees and the isosceles shape needs to have two equal length sides and two equal angles. You might be able to do it with three lines that represent the sides of the triangle but you'd probably need some of the functions of some math library.
0
 
John CarneyReliability Business Tools Analyst IIAuthor Commented:
Hi Martin, I have a code that will calculate the angles of a right triangle if I know the height and width of the triangle. I'm just curious about doing it in reverse and calculating the height and width based on the apex angle. here's the code I'm using to find the angles of a given triangle. Do you see a way to adapt it to work in reverse?

Sub HypAndAngle()
ActiveSheet.Shapes(Application.Caller).Select
 Dim x, y, hyp, angle As Double
 Const Pi = 3.1415926 'defines constant for pi
    x = Selection.ShapeRange.Height
    y = Selection.ShapeRange.Width
    hyp = Round(Sqr(x ^ 2 + y ^ 2), 2) 'calculate hypotenuse
    angle = Round(Atn(y / x) * 180 / Pi, 2) 'round angle to 2 decimals
    [A5] = x
    [B5] = y
 [B6].Value = hyp
 [B7].Value = angle
 [B8] = 90 - angle
 [A2].Select
End Sub

Open in new window


Thanks,
John
0
 
ozoCommented:
x = [B6].Value * Cos([B7].Value*Pi/180)
y = [B6].Value * Sin([B7].Value*Pi/180)
0
 
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now