Consulting

Results 1 to 5 of 5

Thread: Script to Change Chart Titles

  1. #1
    VBAX Newbie
    Joined
    Jan 2015
    Posts
    5
    Location

    Script to Change Chart Titles

    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

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Add this:
    Dim oCh as Chart
        For Each oCh In Charts
            och.Name = Replace(och.Name, "January", "February", 1)
        Next oCh
    Be as you wish to seem

  3. #3
    VBAX Newbie
    Joined
    Jan 2015
    Posts
    5
    Location
    Quote Originally Posted by Aflatoon View Post
    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

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    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
    Be as you wish to seem

  5. #5
    VBAX Newbie
    Joined
    Jan 2015
    Posts
    5
    Location
    Quote Originally Posted by Aflatoon View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •