title: How To Make a Loop Within A Loop In VBA More Efficient?
body: <p>So I removed some of the defining variables and other details for simplicity sake. But I basically have a loop that loops through about 20 rows of populated data, then another loop inside of it that loops through about 2000 rows of data. The basic goal is to to match product codes from the 20 row sheet to product codes in the 2000 row sheet. I'm fairly new with VBA and don't know a lot of the VBA functions I could possibly use to achieve the same result as using loops, so any assistance is appreciated!</p>
  <p>Note: It works perfectly as is, but it just takes a really long time (like 5 minutes) to execute. I've already added in Application.ScreenUpdating = False and Application.Calculation = xlManual</p>
  <pre><code>For iiii = 2 To RLast
  
  For v = 2 To Last2
  
      If ws2.Cells(v, 7) = ws3.Cells(iiii, 1) Then
          If ws2.Cells(v, 1) &lt;&gt; &quot;FLHIGH&quot; And ws2.Cells(v, 1) &lt;&gt; &quot;VLOWER&quot; Then
              AmountCount2 = AmountCount2 + ws2.Cells(v, 8)
              AmountCount = ws2.Cells(v, 9)
              Coun = 1
              Crit1 = ws2.Cells(v, 5)
          Else
              If Cranes(Locat, Forbidden, Forbidden2, Forbidden3, Forbidden4, Forbidden5) = False Then
                  If Coun = 0 Then
                      AmountCount = AmountCount + (ws2.Cells(v, 8) + ws2.Cells(v, 9))
                      Crit2 = ws2.Cells(v, 5)
                      Coun = 1
                  Else
                      AmountCount = AmountCount + (ws2.Cells(v, 8))
                      Crit2 = ws2.Cells(v, 5)
                  End If
              Else 
                  AmountCount = ws2.Cells(v, 9)
                  Crit2 = ws2.Cells(v, 5)
              End If
          End If
      End If
      ws3.Cells(iiii, 4) = AmountCount 
      ws3.Cells(iiii, 5) = AmountCount2 
  Next v
  
  Next iiii
  </code></pre>