0

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.

  • Do you have more than 50 charts, and you only want to do those specific 50? Or are you generally trying to loop through all charts? – BruceWayne Sep 14 '17 at 21:54
  • I have the charts displayed in a 5 x 5 grid, with each row / column having one chart, and I want want all of the charts in column 1 to have the same Min/Max from cells A1 and B1, all of the charts in column 2 to have the same Min/Max from cells A2 and B2, and so on. So in that sense, I do want to loop through all of the charts, but I need to do 5 different loops, or figure out a way to specify which Min/Max gets applied to which chart, if that makes any sense... – Chris G Sep 14 '17 at 22:59
  • I actually just figured it out on my own. I just added another line for: Sheets("Sheet1").ChartObjects("Chart 2.1").Activate below the other line and the code worked perfectly. @BruceWayne, I appreciate that you looked into my question, though! – Chris G Sep 15 '17 at 01:24

0 Answers0