Problem With Looping through Charts

Fireredeel

New Member
Joined
Oct 8, 2019
Messages
5
Hello I have attached my Code below. I keep getting the Run-Time error '424': Object Required on the code in the loop. Any help is greatly appreciated.

Code:
Sub p()


Dim cht As ChartObject
Dim sht As Worksheet
Dim CurrentSheet As Worksheet

Set CurrentSheet = ActiveSheet


For Each cht In ActiveSheet.ChartObjects


    ActiveChart.Axes(xlValue).TickLabels.Font.Color.RGB = RGB(60, 60, 60)
    ActiveChart.Axes(xlCategory).TickLabels.Font.Color.RGB = RGB(60, 60, 60)

   Next cht
End Sub
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hello I have attached my Code below. I keep getting the Run-Time error '424': Object Required on the code in the loop. Any help is greatly appreciated.

Did you mean to use activechart or did you intend cht?

Code:
For Each cht In ActiveSheet.ChartObjects

    With cht.Chart
    
        .Axes(xlValue).TickLabels.Font.Color = RGB(60, 60, 60)
        .Axes(xlCategory).TickLabels.Font.Color = RGB(60, 60, 60)
    
    End With

Next cht
 
Last edited:
Upvote 0
I want to update Multiple Charts on the Sheet that I am on. I tried you code and I know run into a problem Error 91: Object Bariable with block Varible not set. Sorry I am very new to VBA.
 
Last edited by a moderator:
Upvote 0
I want to update Multiple Charts on the Sheet that I am on. I tried you code and I know run into a problem Error 91: Object Bariable with block Varible not set. Sorry I am very new to VBA.
All you did was to substitute your For loop with mine in its entirety correct? I'm not getting any errors otherwise.
 
Upvote 0
What is highlighted when you get the error? Maybe one of your charts does not have one of its axes.
 
Upvote 0
I want to update Multiple Charts on the Sheet that I am on. I tried you code and I know run into a problem Error 91: Object Bariable with block Varible not set. Sorry I am very new to VBA.


That worked! I tried to add Bolding. I am now getting error 438 with both of the lines that bold the lables
Code:
'
' graphaxiscolors Macro
' Change Graph axies Colors
'
' Keyboard Shortcut: Ctrl+Shift+Q
Sub LoopThroughCharts()


    Dim sht As Worksheet
    Dim cht As ChartObject
    Dim ser As Series
    Set CurrentSheet = ActiveSheet


For Each cht In ActiveSheet.ChartObjects


    With cht.Chart
    
        .Axes(xlValue).TickLabels.Font.Color = RGB(60, 60, 60)
        .Axes(xlCategory).TickLabels.Font.Color = RGB(60, 60, 60)
        .Legend.Format.TextFrame2.TextRange.Font.Color.RGB = RGB(60, 60, 60)
            If .Axes(xlValue).Selection.Format.TextFrame2.TextRange.Font.Bold = msoFalse Then
                .Axes(xlValue).Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
            If .Axes(xlCategory).Selection.Format.TextFrame2.TextRange.Font.Bold = msoFalse Then
                .Axes(xlCategory).Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
               If .Legend.Format.TextFrame2.TextRange.Font.Bold = msoFalse Then
                .Legend.Format.TextFrame2.TextRange.Font.Bold = msoTrue
    
    End With




Next cht


End Sub
 
Last edited by a moderator:
Upvote 0
That worked! I tried to add Bolding. I am now getting error 438 with both of the lines that bold the lables

Is this what you want?

Code:
For Each cht In ActiveSheet.ChartObjects

    With cht.Chart
    
        With .Axes(xlValue).TickLabels.Font
            .Color = RGB(60, 60, 60)
            .Bold = True
        End With
        
        With .Axes(xlCategory).TickLabels.Font
            .Color = RGB(60, 60, 60)
            .Bold = True
        End With
        
        With .Legend.Font
            .Color = RGB(60, 60, 60)
            .Bold = True
        End With
        
    End With

Next cht
 
Last edited:
Upvote 0
Last edited:
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

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