humdingaling,
Thanks for putting me on to Jon's website!
I just modified Jon's code so that it handles Chart Objects and Chart Sheets. I used a blunt force method of repeating the code for the Chart Objects and modifying it so that handles Chart sheets also.
Now, if I could figure out how to keep the code from changing the chart type to the same chart type as the master and just format the text in the Titles, data labels and axis units, I would be all set. Any thoughts?
Sub Copy_Chart_Formats_Not_Titles()
Dim Sht As Worksheet
Dim Cht As ChartObject
Dim oChart As Chart
Dim chtMaster As Chart
Dim bTitle As Boolean
Dim bXTitle As Boolean
Dim bYTitle As Boolean
Dim sTitle As String
Dim sXTitle As String
Dim sYTitle As String
Dim iSource As Long
Dim iTarget As Long
Dim iTotal As Long
Dim iSeries As Long
Dim vSource As Variant
Dim vTarget As Variant
Application.ScreenUpdating = False
Set chtMaster = ActiveChart
iSource = chtMaster.SeriesCollection.Count
For Each Sht In ActiveWorkbook.Worksheets
' Debug.Print
' Debug.Print Sht.Name
' Debug.Print Sht.ChartObjects.Count
' Debug.Print
' Debug.Print Sht.Charts.Count
For Each Cht In Sht.ChartObjects
If Sht.Name = chtMaster.Parent.Parent.Name And _
Cht.Name = chtMaster.Parent.Name Then
' don't waste time on chtMaster
Else
With Cht.Chart
' count series
iTarget = .SeriesCollection.Count
' get titles
bTitle = .HasTitle
If bTitle Then
' chart title exists
sTitle = .ChartTitle.Characters.Text
End If
If .HasAxis(xlCategory) Then
bXTitle = .Axes(xlCategory).HasTitle
If bXTitle Then
' axis title exists
sXTitle = .Axes(xlCategory).AxisTitle.Characters.Text
End If
End If
If .HasAxis(xlValue) Then
bYTitle = .Axes(xlValue).HasTitle
If bYTitle Then
' axis title exists
sYTitle = .Axes(xlValue).AxisTitle.Characters.Text
End If
End If
' apply formats
chtMaster.ChartArea.Copy
.Paste Type:=xlFormats
' restore data (2007 and 2010 bug:
' paste-special-formats treated as paste-special-all)
iTotal = .SeriesCollection.Count
If iTotal = iSource + iTarget Then
For iSeries = 1 To iTarget
vSource = Split(.SeriesCollection(iSeries).Formula, ",")
vTarget = Split(.SeriesCollection(iSeries + iSource).Formula, ",")
vTarget(UBound(vTarget)) = vSource(UBound(vSource))
.SeriesCollection(iSeries).Formula = Join(vTarget, ",")
Next
For iSeries = iTotal To iTarget + 1 Step -1
.SeriesCollection(iSeries).Delete
Next
End If
' restore titles
If bTitle Then
.HasTitle = True
.ChartTitle.Characters.Text = sTitle
End If
If bXTitle Then
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Characters.Text = sXTitle
End If
If bYTitle Then
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Characters.Text = sYTitle
End If
End With
End If
Next Cht
Next Sht
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set chtMaster = ActiveChart
iSource = chtMaster.SeriesCollection.Count
For Each Sht In ActiveWorkbook.Worksheets
' Debug.Print
' Debug.Print Sht.Name
' Debug.Print ActiveWorkbook.Charts.Count
' Debug.Print
' Debug.Print Sht.Charts.Count
For Each oChart In ActiveWorkbook.Charts
If Sht.Name = chtMaster.Parent.Parent.Name And _
oChart.Name = chtMaster.Parent.Name Then
' don't waste time on chtMaster
Else
' With oChart.Chart
With oChart
' count series
iTarget = .SeriesCollection.Count
' get titles
bTitle = .HasTitle
If bTitle Then
' chart title exists
sTitle = .ChartTitle.Characters.Text
End If
If .HasAxis(xlCategory) Then
bXTitle = .Axes(xlCategory).HasTitle
If bXTitle Then
' axis title exists
sXTitle = .Axes(xlCategory).AxisTitle.Characters.Text
End If
End If
If .HasAxis(xlValue) Then
bYTitle = .Axes(xlValue).HasTitle
If bYTitle Then
' axis title exists
sYTitle = .Axes(xlValue).AxisTitle.Characters.Text
End If
End If
' apply formats
chtMaster.ChartArea.Copy
.Paste Type:=xlFormats
' restore data (2007 and 2010 bug:
' paste-special-formats treated as paste-special-all)
iTotal = .SeriesCollection.Count
If iTotal = iSource + iTarget Then
For iSeries = 1 To iTarget
vSource = Split(.SeriesCollection(iSeries).Formula, ",")
vTarget = Split(.SeriesCollection(iSeries + iSource).Formula, ",")
vTarget(UBound(vTarget)) = vSource(UBound(vSource))
.SeriesCollection(iSeries).Formula = Join(vTarget, ",")
Next
For iSeries = iTotal To iTarget + 1 Step -1
.SeriesCollection(iSeries).Delete
Next
End If
' restore titles
If bTitle Then
.HasTitle = True
.ChartTitle.Characters.Text = sTitle
End If
If bXTitle Then
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Characters.Text = sXTitle
End If
If bYTitle Then
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Characters.Text = sYTitle
End If
End With
End If
Next oChart
Next Sht
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Application.ScreenUpdating = True
End Sub
Bookmarks