Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / June 2005

Tip: Looking for answers? Try searching our database.

Excel VBA: chart numbering

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marco Shaw - 30 Jun 2005 19:55 GMT
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
Eric Legault [MVP - Outlook] - 30 Jun 2005 21:17 GMT
Wrong group Marco!  Try the Excel programming group.

Signature

Eric Legault - B.A, MCP, MCSD, Outlook MVP
Try Picture Attachments Wizard for Outlook! http://tinyurl.com/ckytm
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

> Outlook 2003 (using macro recorder and chart wizard)
>
[quoted text clipped - 76 lines]
>
> Marco
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.