Excel VBA: chart numbering

M

Marco Shaw

Outlook 2003 (using macro recorder and chart wizard)

What I'm trying to do:

I have some simple VBA to create a pie chart:

Sub pie_chart()
'
' pie_chart Macro
'

'
Range("E1").Select
ActiveCell.FormulaR1C1 = "=RC[-3]"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=R[10]C[-3]"
Range("E3").Select
ActiveCell.FormulaR1C1 = "=R[20]C[-3]"
Range("E4").Select
ActiveCell.FormulaR1C1 = "=R[30]C[-3]"
Range("E5").Select
ActiveCell.FormulaR1C1 = "=R[40]C[-3]"
Range("E6").Select
ActiveCell.FormulaR1C1 = "=R[50]C[-3]"
Range("F1").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:R[10]C[-3])"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=SUM(R[10]C[-3]:R[20]C[-3])"
Range("F3").Select
ActiveCell.FormulaR1C1 = "=SUM(R[20]C[-3]:R[30]C[-3])"
Range("F4").Select
ActiveCell.FormulaR1C1 = "=SUM(R[30]C[-3]:R[40]C[-3])"
Range("F5").Select
ActiveCell.FormulaR1C1 = "=SUM(R[40]C[-3]:R[50]C[-3])"
Range("F6").Select
ActiveCell.FormulaR1C1 = "=SUM(R[50]C[-3]:R[60]C[-3])"
Range("E1:F6").Select
Charts.Add
ActiveChart.ChartType = xl3DPieExploded
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("E1:F6"),
PlotBy:= _
xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Application.CommandBars("Chart").Visible = False
End Sub

Then another simple sub, since I want to break certain things down into
pieces, where this code will simply change the pie chart formatting:

Sub pie_chart2()
'
' pie_chart2 Macro
'

'
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ApplyDataLabels AutoText:=True, LegendKey:=False, _
HasLeaderLines:=True, ShowSeriesName:=False,
ShowCategoryName:=False, _
ShowValue:=False, ShowPercentage:=True, ShowBubbleSize:=False
ActiveChart.PlotArea.Select
Selection.ClearFormats
End Sub

My problem:

I've googled around, played a bit with .Name, but in the 2nd sub, I can't
figure out how to 'activate' the chart created from the 1st sub properly.

I'll have a couple of charts like this on the same sheet, so I should
probably refer to them by name.

Error:
Run-time error '1004':
Unable to get the ChartObjects property of the Worksheet class

Any ideas?

Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Modify range in VBA 9
Excel Excel Macro Help 2
Totals An Easier Way?? 5
I'd like to modify mt Macro ... 9
Macro to shift to next row 2
Change data with a macro 8
Easier Way to Macro Total 4
Macro moving with daily date 2

Top