I'm trying to make my shape change height automatically, based on what is in a cell, when that cell value is changed.
The tricky part is that it would be 1" of height per every 1000 inputted into that cell.
I thought it would be something like the below, but that's based on ranges and doesn't take the ratio into consideration and is pretty tedious.
Private Sub Worksheet_ShapeHeight()
If Range("C8").Value >= 1000 And Range("").Value <= 2000 Then
Shapes("Rectangle 1").Height = 1
Else
If Range("C8").Value >= 2000 And Range("").Value <= 3000 Then
Shapes("Rectangle 1").Height = 2
'---And so on..
End Sub
Perhaps something like the following. Note that the unit for Shape.Height
is points, not inches.
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Me.Range("C8")) Is Nothing Then Exit Sub
Dim calcHeight As Single
calcHeight = Int(Me.Range("C8").Value / 1000) * 72 ' 72 points per inch
Me.Shapes("Rectangle 1").Height = calcHeight
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.