title: Copy Excel Row if Cell is equal to a value
body: <p>I'm trying to copy and paste into a different workbook and spread that data over different sheets inside of the new workbook.  I've got my VBA working, but it only works about 25% of the time.  I continually get an error on "Run-time error '1004': Select method of Range class failed".</p>
  
  <p>Here is the script:</p>
  
  <pre><code>Sub CopyData()
  
      Dim i As Range
      For Each i In Range("A1:A1000")
  
          Windows("data_1.xls").Activate
          Sheets("data_1").Activate
          If i.Value = 502 Then
              i.Select
              ActiveCell.Rows("1:1").EntireRow.Select
              Selection.Copy
              Windows("DataOne.xls").Activate
              Sheets("502").Range("A39").End(xlUp).Offset(1, 0).PasteSpecial
          End If
          If i.Value = 503 Then
              ........
          End If
       Next i
  End Sub
  </code></pre>
  
  <p>The failure happens on <code>i.Select</code> every time.  Do I need to bring <code>Next i</code> up to the end of every <code>End If</code>?  </p>