Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 06-21-2009, 11:15 PM
dontuch_dg dontuch_dg is offline
Registered User
 
Join Date: 16 Jun 2009
Location: san jose ca
MS Office Version:Excel 2007
Posts: 4
dontuch_dg is becoming part of the community
Smile Create Chart Macro from Report - Question

Please Register to Remove these Ads

Hi, I am looking for a suggestion.

The attach file has tab Report with alot of data and charttest.
1. Can all the 6 charts be created by one macro?
2. Use a button to update?

I tried to test my 2 pie charts using the code from the website:
The bottom ActiveCharts has errors.
http://pubs.logicalexpressions.com/P...cle.asp?ID=390

Code:
Sub MyPie()
     
   ' Select the cell in the upper-left corner of the chart.
   Range("ae9").Select
   ' Select the current range of data. This line of code assumes that
   ' the current region of cells is contiguous - without empty rows
   ' or columns.
   Selection.CurrentRegion.Select
   ' Assign the address of the selected range of cells to a variable.
   myrange = Selection.Address
   ' Assign the name of the active sheet to a variable. This line is
   ' used in order to allow a chart to be created on a separate chart
   ' sheet.
   mysheetname = ActiveSheet.Name
   ' Add a chart to the active sheet.
   ActiveSheet.ChartObjects.Add(125.25, 60, 301.5, 155.25).Select
   ' To create a chart on a separate chart sheet, remark out the
   ' previous line, and substitute the next line for the one above.
   ' Charts.Add
   Application.CutCopyMode = False
   ' This line can best be written by recording a macro, and
   ' modifying the code generated by the Microsoft Excel Macro
   ' recorder.
   ActiveChart.ChartWizard _
      Source:=Sheets(mysheetname).Range(myrange), _
      Gallery:=xlPie, Format:=8, PlotBy:=xlRows, _
      CategoryLabels:=1, SeriesLabels:=1, HasLegend:=0, _
      Title:="", CategoryTitle:="", _
      ValueTitle:="", ExtraTitle:=""
      ActiveChart.SeriesCollection(2).HasDataLabels = True      
     
End Sub

Thanks,

Last edited by dontuch_dg; 07-01-2009 at 02:50 PM. Reason: I did not add attachment
Reply With Quote
  #2  
Old 06-22-2009, 04:09 AM
Andy Pope's Avatar
Andy Pope Andy Pope is online now
Forum Guru
 
Join Date: 10 May 2004
Location: Essex, UK
MS Office Version:2003 & 2007 sp2
Posts: 7,223
Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding
Re: Create Chart Macro from Report - Question

Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
__________________
Cheers
Andy
www.andypope.info
Reply With Quote
  #3  
Old 06-22-2009, 04:17 AM
Andy Pope's Avatar
Andy Pope Andy Pope is online now
Forum Guru
 
Join Date: 10 May 2004
Location: Essex, UK
MS Office Version:2003 & 2007 sp2
Posts: 7,223
Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding
Re: Create Chart Macro from Report - Question

These changes wil at least get the code to run

Code:
Sub MyPie()
     
   ' Select the cell in the upper-left corner of the chart.
   Range("ae9").Select
   ' Select the current range of data. This line of code assumes that
   ' the current region of cells is contiguous - without empty rows
   ' or columns.
   Selection.CurrentRegion.Select
   ' Assign the address of the selected range of cells to a variable.
   myrange = Selection.Address
   ' Assign the name of the active sheet to a variable. This line is
   ' used in order to allow a chart to be created on a separate chart
   ' sheet.
   mysheetname = ActiveSheet.Name
   ' Add a chart to the active sheet.
   ActiveSheet.ChartObjects.Add(125.25, 60, 301.5, 155.25).Select
   ' To create a chart on a separate chart sheet, remark out the
   ' previous line, and substitute the next line for the one above.
   ' Charts.Add
   Application.CutCopyMode = False
   ' This line can best be written by recording a macro, and
   ' modifying the code generated by the Microsoft Excel Macro
   ' recorder.
   ActiveChart.ChartWizard _
      Source:=Sheets(mysheetname).Range(myrange), _
      Gallery:=xlPie, Format:=8, PlotBy:=xlColumns, _
      CategoryLabels:=1, SeriesLabels:=1, HasLegend:=0, _
      Title:=""
'      ActiveChart.SeriesCollection(2).HasDataLabels = True
      
     
End Sub
__________________
Cheers
Andy
www.andypope.info
Reply With Quote
  #4  
Old 06-30-2009, 04:54 PM
dontuch_dg dontuch_dg is offline
Registered User
 
Join Date: 16 Jun 2009
Location: san jose ca
MS Office Version:Excel 2007
Posts: 4
dontuch_dg is becoming part of the community
Re: Create Chart Macro from Report - Question

Thanks Andy, I tried to remove the legend and include those labels into the pie? I am new to this site; How do I insert "solved" to threads?
Reply With Quote
  #5  
Old 07-01-2009, 04:12 AM
Andy Pope's Avatar
Andy Pope Andy Pope is online now
Forum Guru
 
Join Date: 10 May 2004
Location: Essex, UK
MS Office Version:2003 & 2007 sp2
Posts: 7,223
Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding Andy Pope Has a higher level of understanding
Re: Create Chart Macro from Report - Question

In the bar above the posts is a menu item How To...? with link to mark a thread solved.
__________________
Cheers
Andy
www.andypope.info
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump