Nat Aes
Nat Aes

Reputation: 927

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?

Upvotes: 9

Views: 46435

Answers (1)

Tim Williams
Tim Williams

Reputation: 166885

Use the .Top and .Left properties
e.g

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

Upvotes: 13

Related Questions