Results 1 to 3 of 3
  1. #1
    Bronze Lounger
    Join Date
    Feb 2008
    Posts
    1,424
    Thanks
    126
    Thanked 5 Times in 5 Posts
    I have 7 graphs per worksheet on several worksheets. The graphs are the same on each worksheet, but relate to the applicable branches data.

    I have written to do the job, but need it streamlined. It would be appreciated if you could assist.

    The code for sheet "Graph PE" is the same a sheet "Graph Uiten". I would like the code simplified so that it is repeated for each of the sheets. I have 13 worksheets with the same graphs, but for different branches, so only the data is different

    Sub Print_Graphs()
    Application.ScreenUpdating = False
    Sheets("Graph PE").Select
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.SeriesCollection(1).Select
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 3").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 4").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 5").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 6").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveChart.Axes(xlValue).MajorGridlines.Select
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Sheets("Graph Uiten").Select
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.SeriesCollection(1).Select
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 3").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 4").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 5").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 6").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveChart.Axes(xlValue).MajorGridlines.Select
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Sheets("Graph Newton").Select
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.SeriesCollection(1).Select
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 3").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 4").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 5").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 6").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveChart.Axes(xlValue).MajorGridlines.Select
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveSheet.ChartObjects("Chart 7").Activate
    ActiveChart.PlotArea.Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Application.ScreenUpdating = True

    End Sub

  2. #2
    5 Star Lounger
    Join Date
    Aug 2004
    Location
    Connecticut, USA
    Posts
    816
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The following assumes the workbook only contains the sheets containing the charts and that all charts on the sheet are to be printed.

    Code:
    Sub printCharts()
    Dim i As Integer, j As Integer, iChart As Integer
    
    Application.ScreenUpdating = False
    For i = 1 To Sheets.Count
    	Sheets(i).Select
    	For j = 1 To Sheets(i).ChartObjects.Count
     	ActiveSheet.ChartObjects(j).Activate
     	ActiveChart.PlotArea.Select
     	ActiveWindow.SelectedSheets.PrintOut Copies:=1
    	Next
    Next
    Application.ScreenUpdating = True
    End Sub

    For easier readability of pasted code, please use the [code] tag when posting. You can either manually enter the tag or click the "<>" above the post box and paste your data between the tags. You can also post your code, highlight the code and then click on the "<>"

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Test reply to try editing post - to be deleted.
    Wendell

Posting Permissions

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