title: Pass active sheet to a sub routine
body: <p>In Excel 2013, I have a worksheet (named "ChartSheet") which has six charts. I'm trying to automatically set the minimum and maximum values of the Y axis of each chart, upon any change within the worksheet. The values for the minimum and maximum values for each chart are contained within named ranges, specific to the <code>ChartSheet</code> worksheet, called <code>rng_MaxAxis</code> and <code>rng_MinAxis</code>.</p>
  
  <p>In order to accomplish my goal I have the following VBA code in the <em>ChartSheet</em> sheet:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
      FormatCharts
  End Sub
  </code></pre>
  
  <p>This feeds off of a SubRoutine I have in a module called <code>FormatCharts</code> and the code in that is:</p>
  
  <pre><code>Sub FormatCharts()
  
  Dim objCht As ChartObject
  Dim maxAxis As Range
  Dim minAxis As Range
  
  Set maxAxis = ActiveSheet.Range("rng_MaxAxis")
  Set minAxis = ActiveSheet.Range("rng_MinAxis")
  
  For Each objCht In ActiveSheet.ChartObjects
      With objCht.Chart
       ' Value (Y) Axis
          With .Axes(xlValue)
              For Each maxValue In maxAxis
                  .MaximumScale = maxValue.Value
              Next maxValue
  
              For Each minValue In minAxis
                  .MinimumScale = minValue.Value
              Next minValue
          End With
      End With
  Next objCht
  
  End Sub
  </code></pre>
  
  <p>Upon any change I receive the following error, <code>Compile Error: Variable not found</code> and it points to the <code>maxValue</code> For Each loop.</p>
  
  <p>I believe this is due to Excel not knowing which worksheet to pass to the <code>FormartCharts</code> subroutine. How can I pass the active sheet to the <code>FormatCharts</code> subroutine?</p>