title: Vba loop for many sheets
body: <p>I have vba code that adds calculations for 4 sheets. I want a loop that will calculate hundreds of sheet without adding sheetname again &amp; again in code. </p>
  
  <pre><code>Private Sub CommandButton2_Click()
  
     Dim TabNames As Variant, Ordinals As Variant
  
     TabNames = Array("4-16 - 4-22", "4-23 - 4-29", "4-30 - 5-6")
     Ordinals = Array("1st", "2nd", "3rd")
  
      For i = 0 To UBound(TabNames, 1)
         Range("A5").Offset(i).Value = TabNames(i)
         Range("B5").Offset(i).Value = Ordinals(i)
         Range("I5").Offset(i).Formula = "=AVERAGE('" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P)"
         Range("J5").Offset(i).Formula = "=COUNTIFS('" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P,""&gt;=""&amp;1)"
         Range("C5").Offset(i).Formula = "=AVERAGEIFS('" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P, '" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P, ""&gt;301"",'" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P, ""&lt;480"")"
         Range("D5").Offset(i).Formula = "=COUNTIFS('" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P,""&gt;""&amp;301,'" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P,""&lt;""&amp;480)"
         Range("F5").Offset(i).Formula = "=AVERAGEIFS('" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P, '" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P, ""&gt;=1"",'" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P, ""&lt;300"")"
         Range("G5").Offset(i).Formula = "=COUNTIFS('" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P,""&gt;=""&amp;1,'" &amp; "adt" &amp; TabNames(i) &amp; "'!$P:$P,""&lt;""&amp;300)"
      Next
      Range("E5:E7,H5:H7,K5:K7").FormulaR1C1 = "=(R2C3-R[0]C[-2])*(R1C4*R[0]C[-1])"
  End Sub
  </code></pre>
  
  <p>Thank you for your help.</p>