简体   繁体   中英

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

Example: If I enter 0 into cell E4, I want the flowchart terminator shape to move to top = 110 and left = 918

That should put the shape directly in the center of the level image as shown below in 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

 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. You check to see if the target is E4 and then check the value of that target (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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM