[英]Moving shape with vba based on cell value
Hoping someone can help me out with this one.希望有人能帮我解决这个问题。
I would like to move the flowchart terminator shape in cell H4 to a specific coordinate based on the value inputted into cell E4我想根据输入到单元格 E4 中的值将单元格 H4 中的流程图终止符形状移动到特定坐标
Example: If I enter 0 into cell E4, I want the flowchart terminator shape to move to top = 110 and left = 918示例:如果我在单元格 E4 中输入 0,我希望流程图终止符形状移动到顶部 = 110 和左侧 = 918
That should put the shape directly in the center of the level image as shown below in H4这应该将形状直接放在关卡图像的中心,如下面的 H4 所示
The only part I have gotten so far is how to move the shape, but I don't know how to correlate the shape movement with a change in cell E4 value到目前为止我得到的唯一部分是如何移动形状,但我不知道如何将形状移动与单元格 E4 值的变化相关联
Public Sub Test() Dim oShape As Shape Set oShape = ActiveSheet.Shapes("Flowchart: Terminator 123") oShape.Top = 110 oShape.Left = 918 End Sub
End Sub结束子
As mentioned you can use the Worksheet_Change()
event.如前所述,您可以使用
Worksheet_Change()
事件。 You check to see if the target is E4 and then check the value of that target (Range obj).您检查目标是否为 E4,然后检查该目标的值 (Range obj)。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("E4").Address Then
If Target.Value = 0 Then
ActiveSheet.Shapes("Flowchart: Terminator 123").Top = 110
ActiveSheet.Shapes("Flowchart: Terminator 123").Left = 918
End If
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.