title: Check checkbox value only once inside a nested loop
body: <p>I am checking the value of a checkbox on my userform inside a nested loop. I want to know if there is a way to do this before the loops because basically the code is running the same check over and over again...</p>
  <p>what it is doing is it loops through the entire column B and combines all the rows that have the same conditions. then it puts in into an array and prints. So I need to do this checkbox check twice. Any help is appreciated!</p>
  <pre><code>Dim dict As Object
  Dim LastRow As Long
  Dim aCell As Range
  Dim ArrayLen As Long
  Dim LArr() As Single
  Dim MPch As Boolean
  
  MPch = UserForm1.MPCheck1.Value
  Set dict = CreateObject(&quot;scripting.dictionary&quot;)
          X = 0
          
    With wks
    
          LastRow = .Cells(.Rows.Count, &quot;B&quot;).End(xlUp).row
          ReDim LArr(LastRow)
  
          For Each aCell In .Range(&quot;B2:B&quot; &amp; LastRow)
              
                  If MPch = True Then
                      UniqueCombo = aCell.Value &amp; &quot;,&quot; &amp; aCell.Offset(0, 1) &amp; aCell.Offset(0, 2)
                  Else
                      UniqueCombo = aCell.Value &amp; &quot;,&quot; &amp; aCell.Offset(0, 1) &amp; aCell.Offset(0, 2) &amp; &quot;,&quot; &amp; aCell.Offset(0, 5)
                  End If
              
              DieCoordinate = aCell.Value &amp; &quot;,&quot; &amp; aCell.Offset(0, 1)
              SheetName = aCell.Offset(0, 2) &amp; &quot;-&quot; &amp; aCell.Offset(0, 5)
          
                  If Not dict.exists(UniqueCombo) Then
                      VarLastRow = ThisWorkbook.Worksheets(SheetName).Cells(.Rows.Count, &quot;E&quot;).End(xlUp).row + 1
                      ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 5) = DieCoordinate
                      dict(UniqueCombo) = True 'add this value
                                             
                      For o = 2 To LastRow
                          
                          If MPch = True Then
                              VariableCombo = .Cells(o, 2) &amp; &quot;,&quot; &amp; .Cells(o, 3) &amp; .Cells(o, 4)
                          Else
                              VariableCombo = .Cells(o, 2) &amp; &quot;,&quot; &amp; .Cells(o, 3) &amp; .Cells(o, 4) &amp; &quot;,&quot; &amp; .Cells(o, 7)
                          End If
                      
                          VariableCombo = .Cells(o, 2) &amp; &quot;,&quot; &amp; .Cells(o, 3) &amp; .Cells(o, 4) &amp; &quot;,&quot; &amp; .Cells(o, 7)
  
                              If UniqueCombo = VariableCombo And .Cells(o, 6).Interior.ColorIndex = -4142 And _
                              .Cells(o, 6) &lt;&gt; &quot;*&quot; And .Cells(o, 6) &lt;&gt; &quot;0&quot; And .Cells(o, 6) &lt;&gt; &quot;&quot; Then
  
                                  CDTot = CDTot + .Cells(o, 6)
                                  LArr(X) = .Cells(o, 6)
                                  X = X + 1
        
                              End If
      
                      Next
        
                          If X = 0 Then
                              ArrayLen = 0
                              Else
                              ReDim Preserve LArr(UBound(LArr) - (LastRow - X + 1))
                              ArrayLen = UBound(LArr) - LBound(LArr) + 1
                          End If
            
                          If ArrayLen &lt; UserForm1.TextBox7 Then
                           ThisWorkbook.Worksheets(SheetName).Range(ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 5), ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 10)).Interior.ColorIndex = 53
                          End If
       
                          LCDUCD = 3 * Application.WorksheetFunction.StDev_P(LArr)
                          DieAver = Application.WorksheetFunction.Average(LArr)
          
                          ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 7) = LCDUCD
                          ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 6) = DieAver
                          ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 8) = aCell.Value
                          ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 9) = aCell.Offset(0, 1).Value
                          ThisWorkbook.Worksheets(SheetName).Cells(VarLastRow, 10) = ArrayLen
                         
                  
                  End If
                  
                  ReDim LArr(LastRow)
                  X = 0
          Next aCell
          
  </code></pre>
  <p>End With</p>