PDA

View Full Version : Script to Change Chart Titles



aadil177
02-29-2016, 07:17 AM
Hi,

I use this script to change the titles of charts in worksheets. I would like to know how this script can be modified to change the titles of ChartSheets.


Sub dotitles()
For Each sh In Worksheets
For Each ch In sh.ChartObjects
If ch.Chart.HasTitle Then
ch.Chart.ChartTitle.Text = Replace(ch.Chart.ChartTitle.Text, "January", "February", 1)
End If
Next
Next

End Sub

Please advise

Thank you

Aflatoon
02-29-2016, 07:34 AM
Add this:

Dim oCh as Chart
For Each oCh In Charts
och.Name = Replace(och.Name, "January", "February", 1)
Next oCh

aadil177
02-29-2016, 08:36 AM
Add this:

Dim oCh as Chart
For Each oCh In Charts
och.Name = Replace(och.Name, "January", "February", 1)
Next oCh


Hi I could not get it to work:


Sub dotitles()
Dim oCh As Chart
For Each oCh In Charts
oCh.Name = Replace(oCh.Name, "January", "February", 1)
Next oCh
For Each sh In Sheets
For Each ch In sh.ChartObjects
If ch.Chart.HasTitle Then
ch.Chart.ChartTitle.Text = Replace(ch.Chart.ChartTitle.Text, "January", "February", 1)
End If
Next
Next

End Sub

Aflatoon
02-29-2016, 08:48 AM
Apologies - I misunderstood. I think you want:

For Each oCh In Charts
If oCh.HasTitle Then
oCh.ChartTitle.Text = Replace(oCh.ChartTitle.Text, "January", "February", 1)
End If
Next oCh

aadil177
02-29-2016, 08:54 AM
Apologies - I misunderstood. I think you want:

For Each oCh In Charts
If oCh.HasTitle Then
oCh.ChartTitle.Text = Replace(oCh.ChartTitle.Text, "January", "February", 1)
End If
Next oCh


Excellent, thank you very much :clap2: