title: looping until certain value is found
body: <p>I have a following problem (and an urging desire to overcome it:)). I need to make my loop to go through rows until certain value is found. Let me demonstrate what I need in more detail on my code:  </p>
  
  <pre><code>For x = 1 To 1000
      If Cells(x, "O").Value = "P" Or Cells(x, "O").Value = "R" Then
  
          Dim i As Integer
          For i = 1 To 121
              If Worksheets(Cells(x, "P").Value).Cells(Cells(x, "Q").Value + i, "C") = "" Then
                  With Worksheets(Cells(x, "P").Value)
                      .Cells(Cells(x, "Q").Value + i, "A").Resize(, 20).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                      Range("F" &amp; x, "H" &amp; x).Copy
                      .Cells(Cells(x, "Q").Value + i, "E").PasteSpecial xlPasteAll
                      .Cells(Cells(x, "Q").Value + i, "C") = "Pur"
                      Range("AI" &amp; x).Copy
                      .Cells(Cells(x, "Q").Value + i, "O").PasteSpecial xlPasteAll
                  End With
              End If
          Next i
  
      End If  
  </code></pre>
  
  <p>This code simply goes through rows, and when a specified cell, in this case cell in column "C", is empty it does all the copying and pasting. BUT! It does it as much time as I have denoted it (For i = 1 To 121). What I need is a loop that would loop trough rows until first empty cell in column "D" appears, then perform all the copying and pasting and then STOP. What can I do in order to achieve that?  </p>
  
  <p>Please let me know if my question is vague or hard to understand in any way.  </p>
  
  <p>As mehow suggested I update my question with a presentation of my try:<br>
  Changes are marked with comments  </p>
  
  <pre><code>Dim a As Integer 'I introduced new variable
  a = 121          'This is it
  
  For x = 1 To 1000
  If Cells(x, "O").Value = "P" Or Cells(x, "O").Value = "R" Then
  
      Dim i As Integer
      For i = 1 To a 'Changes
          If Worksheets(Cells(x, "P").Value).Cells(Cells(x, "Q").Value + i, "C") = "" Then
              With Worksheets(Cells(x, "P").Value)
                  .Cells(Cells(x, "Q").Value + i, "A").Resize(, 20).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                  Range("F" &amp; x, "H" &amp; x).Copy
                  .Cells(Cells(x, "Q").Value + i, "E").PasteSpecial xlPasteAll
                  .Cells(Cells(x, "Q").Value + i, "C") = "Pur"
                  Range("AI" &amp; x).Copy
                  .Cells(Cells(x, "Q").Value + i, "O").PasteSpecial xlPasteAll
              End With
          a = i ' This way I wanted to end the loop sooner
          End If
      Next i
  
  End If
  </code></pre>