title: Excel VBA - How can I determine number of row label fields in Pivot Table?
body: <p>I have an Excel 2010 pivot table containing, initially, 3 row label fields.</p>
  
  <p>I need to create a macro that will add a certain field as the lowest row label field in the pivot table. (For reasons I won't go into, the user can't add this field in the normal way themselves.)</p>
  
  <p>However, by the time the user runs this macro, they may have added or removed some row labels.</p>
  
  <p>The macro recorder gives me this when I add a field in the lowest position of a pivot table (with 3 row labels already selected):</p>
  
  <pre><code>With ActiveSheet.PivotTables("MyPivotTable").PivotFields("MyNewField")
      .Orientation = xlRowField
      .Position = 4
  End With
  </code></pre>
  
  <p>If the user has added or removed some items, this position number 4 is incorrect. How would I pass into my code the correct position number? </p>
  
  <p>Trying to aim high using <code>Position = 99</code> gives me the following error:</p>
  
  <blockquote>
    <p>Unable to set the Position property of the PivotField class</p>
  </blockquote>
  
  <p>Any ideas please?</p>