Absolute Position of Chart Using VBA

Nat Aes picture Nat Aes · Jan 9, 2014 · Viewed 39.3k times · Source

I can use VBA to create a clustured column charty using the following code:

ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered

However this is normally positioned in the centre of my screen. I can have it moved using code such as the following:

ActiveSheet.Shapes("Chart 1").IncrementLeft -650.4545669291
ActiveSheet.Shapes("Chart 1").IncrementTop -295.9091338583

However this is only relative to its original position. Is it possible to set it that will always be positioned at a certain pixels or cell number? In other words can I code VBA to have create the chart in a certain position on the worksheet?

Answer

Tim Williams picture Tim Williams · Jan 9, 2014

Use the .Top and .Left properties
e.g

With ActiveSheet.Shapes("Chart 1")
    .Left = Range("C10").Left
    .Top = Range("C10").Top
End With