+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    06-16-2009
    Location
    san jose ca
    MS-Off Ver
    Excel 2007
    Posts
    4

    Smile Create Chart Macro from Report - Question

    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 03:50 PM. Reason: I did not add attachment

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,938

    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

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,938

    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

  4. #4
    Registered User
    Join Date
    06-16-2009
    Location
    san jose ca
    MS-Off Ver
    Excel 2007
    Posts
    4

    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?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,938

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0