How to Select Multiple, Specific Charts to be Re-Scaled in Excel with VBA?

621 views Asked by At

I have some VBA code that allows me to re-scale the axes on several different charts. However, I'm trying to adjust that code so that I can select multiple charts to be re-scaled without having to duplicate the code.

A sample of the code I have so far is this:

Sheets("Sheet1").ChartObjects("Chart 1.1").Activate
ActiveChart.Axes (xlValue)
With ActiveChart.Axes(xlValue)
  .MinimumScale = Sheets("Sheet2").Range("A1").Value
  .MaximumScale = Sheets("Shee2").Range("B1").Value
 End With

Sheets("Sheet1").ChartObjects("Chart 1.2").Activate
ActiveChart.Axes (xlValue)
With ActiveChart.Axes(xlValue)
   .MinimumScale = Sheets("Sheet2").Range("B1").Value
   .MaximumScale = Sheets("Sheet2").Range("B2").Value
End With

However, I am eventually going to have 50 charts (Chart 1.1 thru 1.5, Chart 2.1 thru 2.5, ..., Chart 5.1 thru Chart 5.5). I've been trying to figure out whether I can do more with the first line of the code that allows me to select specific charts all at once, but have so far been unsuccessful. Ideally, I'm hoping for something like this:

Sheets("Sheet1").ChartObjects("Chart 1.1", "Chart 2.1", "Chart 3.1", "Chart 4.1", "Chart 5.1").Activate

My VBA coding skills currently consist of what I can figure out via Google, so any suggestions would be greatly appreciated. Thanks.

0

There are 0 answers