Avatar of John Carney
John Carney
Flag for United States of America asked on

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
Microsoft ExcelVBA

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Martin Liss

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.
John Carney

ASKER
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
ASKER CERTIFIED SOLUTION
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Martin Liss

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Your help has saved me hundreds of hours of internet surfing.
fblack61