Find & Replace Chart Name for a Single Chart

The_Rock

Board Regular
Joined
Jul 2, 2007
Messages
174
Hi Folks
I've found online a way to find and replace words in a title for all charts on a sheet but I want to be able to specify specific charts.
In the example below, I only want to update Chart 11.
As I turned off the For/Next statement, I set ch as ChartObject
It crashes on the first line of the IF statement and am out of idea's how else to write the macro.

Please help!

Code:
Sub Change_to_millions()
    Dim xWs As Worksheet: Set xWs = Application.ActiveSheet
    Dim xFindStr As String
    Dim xReplace As String
    Dim ch As ChartObject
    xFindStr = "000s"
    xReplace = "Millions"

    ActiveSheet.ChartObjects("Chart 11").Activate
'For Each ch In xWs.ChartObjects
    If ch.Chart.HasTitle Then
        ch.Chart.ChartTitle.Text = VBA.Replace(ch.Chart.ChartTitle.Text, xFindStr, xReplace, 1)
    End If
'Next
    Call Millions
End Sub

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi, try replacing this line:
Code:
ActiveSheet.ChartObjects("Chart 11").Activate

With
Code:
Set ch = ActiveSheet.ChartObjects("Chart 11")
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top