Link to home
Start Free TrialLog in
Avatar of IT SSM
IT SSMFlag for Australia

asked on

Change Height of triangle to grid with user input.

I want to create a spreadsheet with a right angle triangle. I want to adjust the height of the triangle based on a user input.
The Point of the triangle will always be on 1-1. I want to adjust the height of the triangle up and down the scale on the right axis.
If you can point me to a resource happy to learn this myself or if you have a solution that would be great.
Triangle.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IT SSM

ASKER

Thanks Saqib that will work nicely.
You may try something like below. Assign the following code to a button or triangle itself so that when the button or triangle is clicked, it will ask the user to input the desired triangle height and the height of the triangle will be adjusted accordingly.

In the attached, I have assigned the code to the triangle itself, you can click the triangle to run the code.
Sub AdjustHeightOfTriangle()
Dim ws As Worksheet
Dim shp As Shape
Dim heightInput As Integer

Set ws = Sheets("Sheet1")
Set shp = ws.Shapes("Right Triangle 125")
heightInput = Int(Application.InputBox("Input the desired height of triangle.", "Triangle Height!", Type:=1))

If heightInput = 0 Then
    MsgBox "Height cannot be 0.", vbExclamation
    Exit Sub
ElseIf heightInput > 26 Then
    MsgBox "Height cannot be greater than 26.", vbExclamation
    Exit Sub
End If
shp.Height = 15
shp.Top = ws.Range("C27").Top
shp.ScaleHeight heightInput, msoFalse, msoScaleFromBottomRight
End Sub

Open in new window

Triangle.xlsm