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
and here is the unsuccessful code for the pivot chartsCode:Dim Worksheet As Worksheet Set Worksheet = ThisWorkbook.Worksheets("Tables") For Each PivotTable In Worksheet.PivotTables With PivotTable .RefreshTable End With Next PivotTable
Code breaks on this lineCode: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
With the phraseCode:For Each Chart In ChartObject.Chartssigh. so close.Object doesn't support this property or method
EDIT: see follow-up question below
Last edited by kuraitori; 03-15-2010 at 06:00 PM.
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
Works wonderfully, thank you so much
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.
You can use the macro recorder to get most of the code.
You will also need to use the SeriesCollection and Datalabels collections.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks