title: Loop Through CheckBox Controls in VBA UserForm
body: <p>I have a user form in Excel VBA with a check box for each month.</p>
  
  <p>Selecting one or more cause the required month to be shown on the sheet, I copy-pasted the code 12 times and it works but I'm sure there is a better way doing it with a <code>For</code> loop.</p>
  
  <p>This is a part of my code (it goes on 12 times):</p>
  
  <pre><code>    If CheckBox1.Value = True Then
          ActiveSheet.PivotTables("PivotTable1").PivotFields("month").PivotItems("1").Visible = True
      Else
         ActiveSheet.PivotTables("PivotTable1").PivotFields("month").PivotItems("1").Visible = False
      End If
  
      If CheckBox2.Value = True Then
          ActiveSheet.PivotTables("PivotTable1").PivotFields("month").PivotItems("2").Visible = True
      Else
         ActiveSheet.PivotTables("PivotTable1").PivotFields("month").PivotItems("2").Visible = False
      End If
  </code></pre>
  
  <p>I tried writing:</p>
  
  <pre><code>for i in range 1 to 12
  </code></pre>
  
  <p>and then writing my code but there seem to be a problem when I put "i" instead of the numbers.</p>