+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    06-28-2009
    Location
    boston, ma
    MS-Off Ver
    Excel 2003
    Posts
    2

    Apply default chart to multiple worksheets?

    Hi,

    I have a chart format that I want to apply to same data format through 100's separate worksheets in one work.

    1. Apply custom chart template
    2. Change column titles from series 1,2,3,4 to may, apr, mar, feb, oct
    3. Change chart titles to coo function for y axis and time for x axis

    I have done this already by recording separate marcos but applying it to 100's of worksheets does not work.

    Can anyone help?

    Best,

    Frank

  2. #2
    Forum Contributor
    Join Date
    04-03-2007
    Location
    Auckland, New Zealand
    MS-Off Ver
    2007
    Posts
    137

    Re: Apply default chart to multiple worksheets?

    Hi,
    Are you able to post an example of say 3 sheets and the code you've recorded as an attached file.

    Always easier to work with examples

  3. #3
    Registered User
    Join Date
    02-06-2005
    Posts
    16

    Re: Apply default chart to multiple worksheets?

    Hi,

    Sorry for the delay but here is an example of what i am trying to do. I want to apply this chart template to the data in the worksheets.
    Attached Files Attached Files

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

    Re: Apply default chart to multiple worksheets?

    Should your chart not be a xy-scatter rather than a Line chart type?
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    02-06-2005
    Posts
    16

    Re: Apply default chart to multiple worksheets?

    This is the correct file format for this type of dataset :-)

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

    Re: Apply default chart to multiple worksheets?

    Here is a routine to duplicate the chart across the sheets.
    It should also work with other workbooks, taking the existing chart from the Title sheet and copying it across.

    I realise it's your data and your chart but just check the difference in the plots by comparing the copied chart to the existing one on sheet2.

    The xy-scatter has true value axis rather than category one that the line provides. I'm sure you would agree that the outcome of the lines is radically different.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    02-06-2005
    Posts
    16

    Re: Apply default chart to multiple worksheets?

    Hi,

    Thank you for the input and the x domain is not linear time but it is a sampling time (i can explain application offline).

    The time domain x will be the sample for all the measurements. We will then have different number of replicates. It could be anywhere from 3-15 replicates.

    We would like to average the number of replicates, obtain standard deviation, % relative std deviation and plot the chart to the right side of the data.

    Here is a file of what we are trying to do with a macro i recorded. If we could automate the data processing side and add the chart component that your provided. We would dramatically reduce our data processing time and help us do some real science :-)

    Frank
    Attached Files Attached Files

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

    Re: Apply default chart to multiple worksheets?

    Try this code modification for adding 3 calculated columns.
    Code:
    Sub X()
    
        Dim chtTemplate As Chart
        Dim shtTemp As Worksheet
        Dim lngLastRow As Long
        Dim chtLocal As Chart
        Dim lngCol As Long
        Dim lngSeries As Long
        Dim objSeries As Series
            
        Set chtTemplate = ThisWorkbook.Worksheets("Title").ChartObjects(1).Chart
        Application.ScreenUpdating = False
        
        For Each shtTemp In ActiveWorkbook.Worksheets
            If shtTemp.Name <> chtTemplate.Parent.Parent.Name Then
                If shtTemp.Cells(4, 1) <> "" Then
                    lngLastRow = shtTemp.Cells(shtTemp.Rows.Count, 1).End(xlUp).Row
                    With chtTemplate.Parent
                        .Copy
                        shtTemp.Paste
                        Set chtLocal = shtTemp.ChartObjects(shtTemp.ChartObjects.Count).Chart
                        
                        With chtTemplate.Parent
                            chtLocal.Parent.Left = .Left
                            chtLocal.Parent.Top = .Top
                            chtLocal.Parent.Width = .Width
                            chtLocal.Parent.Height = .Height
                        End With
                    End With
                    
                    lngCol = 2
                    Do While shtTemp.Cells(4, lngCol) <> ""
                        If lngCol - 1 <= chtTemplate.SeriesCollection.Count Then
                            ' Use existing series
                            Set objSeries = chtLocal.SeriesCollection(lngCol - 1)
                        Else
                            Set objSeries = chtLocal.SeriesCollection.NewSeries
                        End If
                        With objSeries
                            ' update range reference
                            .Name = shtTemp.Cells(4, lngCol)
                            .Values = shtTemp.Range(shtTemp.Cells(5, lngCol), shtTemp.Cells(lngLastRow, lngCol))
                        End With
                        lngCol = lngCol + 1
                    Loop
                    
                    With shtTemp
                        .Cells(4, lngCol).Resize(1, 3) = Array("Average", "Standard Deviation", "% RSD")
                        'Average
                        shtTemp.Cells(5, lngCol).Formula = "=AVERAGE(B5:" & .Cells(5, lngCol - 1).Address(False, False) & ")"
                        ' STDEV
                        shtTemp.Cells(5, lngCol + 1).Formula = "=STDEV(B5:" & .Cells(5, lngCol - 1).Address(False, False) & ")"
                        ' %RSD
                        shtTemp.Cells(5, lngCol + 2).Formula = "=(" & _
                                                                    .Cells(5, lngCol + 1).Address(False, False) & "/" & _
                                                                    .Cells(5, lngCol).Address(False, False) & ")*100"
                        ' Populate all rows
                        .Range(.Cells(5, lngCol), .Cells(lngLastRow, lngCol + 2)).FillDown
                    End With
                End If
            End If
        Next
        Application.ScreenUpdating = True
    End Sub
    Cheers
    Andy
    www.andypope.info

  9. #9
    Registered User
    Join Date
    02-06-2005
    Posts
    16

    Re: Apply default chart to multiple worksheets?

    thank you so much. This is awesome

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