Set X-Axis Limits in VBA Loop

cc1987

New Member
Joined
Mar 4, 2016
Messages
18
I'm trying to set the x-axis limits for all charts in a worksheet equal to cell values thorugh a loop but I haven't been able to quite get it working yet.

VBA Code:
Sub ChartSheets_Loop()

Dim cht As ChartObject

  Application.ScreenUpdating = False

      'Determine Maximum value
          MaxNumber = Sheet3.Range("S4").Value
        
        'Determine Minimum value
          MinNumber = Sheet3.Range("S3").Value

  For Each cht In Sheet3.ChartObjects
      
    'Rescale X-Axis
    cht.Activate
    cht.Chart.Axes(xlCategory).MinimumScale = MinNumber
    cht.Chart.Axes(xlCategory).MaximumScale = MaxNumber
  Next cht

   Application.ScreenUpdating = True

End Sub

I've looked at various threads and posts on similar but there's something I haven't got quite right with my code.
 
Thanks will try later and report back.

In the meantime I created a UDF as a work around which will do for now.
 
Upvote 0

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.

Forum statistics

Threads
1,224,846
Messages
6,181,304
Members
453,031
Latest member
Chris_1

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