+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    vba - formatting multiple pivot charts?

    Hello All,

    So found out how to format pivot tables using a for each...in .... loop, but need to do the same for pivot charts, and one bit of code is off.

    Here is the successful code for pivot tables
    Code:
    Dim Worksheet As Worksheet
    Set Worksheet = ThisWorkbook.Worksheets("Tables")
    For Each PivotTable In Worksheet.PivotTables
        With PivotTable
            .RefreshTable
        End With
    Next PivotTable
    and here is the unsuccessful code for the pivot charts
    Code:
    Dim Worksheet As Worksheet
    Set Worksheet = ThisWorkbook.Worksheets("Charts")
    For Each ChartObject In Worksheet.ChartObjects
        For Each Chart In ChartObject.Charts
        With Chart
            .ChartType = xlLine
            .Axes(xlCategory).TicklLabels.Font.Size = 10
            .Axes(xlValue).TicklLabels.Font.Size = 10
        End With
        Next Chart
    Next ChartObject
    Code breaks on this line
    Code:
          For Each Chart In ChartObject.Charts
    With the phrase
    Object doesn't support this property or method
    sigh. so close.


    EDIT: see follow-up question below
    Last edited by kuraitori; 03-15-2010 at 06:00 PM.

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

    Re: vba - formatting multiple pivot charts?

    Avoid using variables names that are already being used as object names.

    a chartobject does not have multiple charts.

    Code:
    Dim shtTemp As Worksheet
    Dim objCht as chartobject
    
    Set shtTemp = ThisWorkbook.Worksheets("Charts")
    For Each objCht In shtTemp.ChartObjects
        
        With objCht.Chart
            .ChartType = xlLine
            .Axes(xlCategory).TicklLabels.Font.Size = 10
            .Axes(xlValue).TicklLabels.Font.Size = 10
        End With
    
    Next
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Re: vba - formatting multiple pivot charts?

    Works wonderfully, thank you so much

  4. #4
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Re: vba - formatting multiple pivot charts?

    Quick Question,

    How do I do the same with Datalabels?

    add datalabels, delete datalabels, and font size = 10 (for datalabels)

    There is a flexable number of series in the data collection.

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

    Re: vba - formatting multiple pivot charts?

    You can use the macro recorder to get most of the code.

    You will also need to use the SeriesCollection and Datalabels collections.
    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