title: Avoiding the use of Activate and Select when working with charts (Excel)
body: <p>I know that using <code>Activate</code> and <code>Select</code> in Excel VBA is not best practice.  I've seen references on how to avoid them when dealing with Ranges (example: <a href="https://stackoverflow.com/questions/10714251/excel-macro-avoiding-using-select" title="LINK">LINK</a>).  How can I avoid them when dealing with <code>ChartObjects</code> (or anything other than Ranges, in general)?</p>
  
  <p>For instance, a way to modify the maximum value on the y-axis using <code>Activate</code> and <code>Select</code> would look something like this (which works):</p>
  
  <pre><code>        ActiveSheet.ChartObjects("MyChart").Activate
          ActiveChart.Axes(xlValue).Select
          ActiveChart.Axes(xlValue).MaximumScale = Range("MaxVal").Value
  </code></pre>
  
  <p>In order to avoid using <code>Activate</code> and <code>Select</code>, I tired to declare variables, and work with those, but that does not work:</p>
  
  <pre><code>     Dim ws As Worksheet
       Set ws = Worksheets("Chart")
       With ws.ChartObjects("MyChart").Axes(xlValue)
          .MaximumScale = Range("MaxVal").Value
       End With
  </code></pre>
  
  <p>The code above runs (i.e. does not throw an error), but the scale on the axis does not change.  What am I missing?</p>
  
  <hr>
  
  <p>EDIT: Got it to work with this "longwinded" version:</p>
  
  <pre><code>    With Worksheets("Chart").ChartObjects("MyChart").Chart.Axes(xlValue)
          .MaximumScale = Range("MaxVal").Value
      End With
  </code></pre>