Loop through worksheets and format chart 1: run time error

suremac

New Member
Joined
Jan 27, 2014
Messages
49
Greetings,


I wrote a chart formatting macro, which works when applied to a specific sheet, and I'm trying use it in a for each loop. The macro is supposed to loop through a list of sheets and only format chart 1. I'm getting a "run time error 438: object doesn't support this property or method" at this line:


Code:
 .ActiveChart.Shapes("TextBox 1").TextFrame.Characters.Text = "Bodily Injury (BI) Liability Claim Trends" & vbLf & " 2005-" & Range("K5").Value & " Percentage Change"

Here is my for each loop:


Code:
Sub UpdateTextAllStateCharts()
    'This macro loops through worksheets in a list and performs the assigned task
    Dim sheet_name As Range
    For Each sheet_name In Sheets("WS").Range("C:C")
        If sheet_name.Value = "" Then
            Exit For
        Else
            With Sheets(sheet_name.Value)
                .ChartObjects("Chart 1").Activate
                .ActiveChart.Shapes("TextBox 1").TextFrame.Characters.Text = "Bodily Injury (BI) Liability Claim Trends" & vbLf & " 2005-" & Range("K5").Value & " Percentage Change" 
               .ChartObjects("Chart 1").Activate
               With ActiveChart.Shapes("TextBox 1").TextFrame.Characters
               With .Font
               .Name = "Calibri"
               .Size = 14
               .FontStyle = "Regular"
               End With
               With ActiveChart.Shapes("TextBox 1").TextFrame
               With .Characters(42, 68).Font
              .FontStyle = "Italic"
              .Size = 12
              End With
              End With
              End With
            End With
        End If
        Next sheet_name
    End Sub

This line is also causing the same error:



Code:
With .Characters(42, 68).Font

Thanks in advance for any help.


Regards,
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Does every sheet have a Chart 1? Does every Chart 1 have a TextBox 1 associated with it?
Does every TextBox 1 contain at least 100 characters?
 
Upvote 0
Hi JoeMo, thanks for the reply. To your questions: yes, yes, and no. Each TextBox 1 contains 68 characters. With a lot of trial and error, this solved the first error:

Code:
Sheets(sheet_name.Value).Chartobjects("Chart 1").Chart.Shapes("TextBox1").TextFrame.Characters.Text = "Bodily Injury (BI) Liability Claim Trends" & vbLf & " 2005-" & Range("K5").Value & " Percentage Change"

Not sure why though. I moved around the
Code:
end with
statements to solve the second error.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,609
Members
452,660
Latest member
Zatman

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