Set X-Axis Limits in VBA Loop

cc1987

New Member
Joined
Mar 4, 2016
Messages
16
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.
 

cc1987

New Member
Joined
Mar 4, 2016
Messages
16
Thanks will try later and report back.

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

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Watch MrExcel Video

Forum statistics

Threads
1,130,046
Messages
5,639,757
Members
417,108
Latest member
Thein Than

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
Top