[英]How to change a shape's height based on a cell value?
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.棘手的部分是每 1000 个输入到该单元格的高度将是 1"。
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.请注意,
Shape.Height
的单位是磅,而不是英寸。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.