Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute Position of Chart Using VBA

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?

like image 579
Nat Aes Avatar asked Jan 09 '14 18:01

Nat Aes


1 Answers

Use the .Top and .Left properties
e.g

With ActiveSheet.Shapes("Chart 1")
    .Left = Range("C10").Left
    .Top = Range("C10").Top
End With
like image 59
Tim Williams Avatar answered Sep 24 '22 00:09

Tim Williams