Home > database >  Moving shape with vba based on cell value
Moving shape with vba based on cell value

Time:03-14

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

enter image description here

CodePudding user response:

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
  • Related