Reputation: 79
Why does this line below doesn't work?
ActiveSheet.Shapes.AddChart2(204, xlColumnClustered).Select
but this one do
graphe_clos.Cells(2, 1).Select
ActiveSheet.Shapes.AddChart2(204, xlColumnClustered).Select
And i intend to create multiple chart and pivot table on the same sheet so do i need to always specify a cell?
Upvotes: 0
Views: 198
Reputation: 29556
This should work (had to add .Chart
in the with
statement)
with ActiveSheet.Shapes.AddChart2(204, xlColumnClustered).Chart
.ClearToMatchStyle
.ChartStyle = 257
.HasTitle = True
.ChartTitle.Text = " Nombre d'évènement"
end with
However, the properties .ShowValueFieldButtons
and .ShowValueFieldButtons
are not valid (I think they are valid only for PivotCharts). It gives error messages no matter if or if not using ActiveChart
.
As a general advice: Read How to avoid using Select in Excel VBA
Upvotes: 1
Reputation: 3053
Use .AddChart instead of .AddChart2. That works for me. Then later you can edit the chart properties in a With block.
Upvotes: 1