title: Excel VBA For-Next Loop to extract data from one WB to another
body: <p>I am working on a for loop that extracts entire rows of data based on the string in the 12th column being equal to "Airfare."</p>
  
  <p>The idea is to copy the rows of data where column 12 (EXPENSE_TYPE) is Airfare and paste it into a second workbook. </p>
  
  <p>My code, below, is not properly looping through all 120 rows of data. When I run my macro, it only extracts the first row of data where my criteria is met. Let me know if you can find my issue. Thanks!</p>
  
  <pre><code>Sub exportDataToOtherWorkbook()
  Dim lastRow As Long
  Dim i As Long
  Dim p As Integer
  Dim q As Integer
  Dim erow As Long
  
  lastRow = ActiveSheet.Range("A" &amp; Rows.Count).End(xlUp).Row
  
  For i = 2 To lastRow
      If Cells(i, 12) = "Airfare" Then
      Range(Cells(i, 1), Cells(i, 16)).Select
      Selection.Copy
  
  
  Workbooks.Open Filename:="C:\users\andrew.godish\Desktop\Practice Files\masterPracticeExtractDataWBtoWB.xlsx"
  
  p = Worksheets.Count
      For q = 1 To p
          If ActiveWorkbook.Worksheets(q).Name = "Sheet2" Then
          Worksheets("Sheet2").Select
          End If
      Next q
  
      erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
  
      ActiveSheet.Cells(erow, 1).Select
      ActiveSheet.Paste
      ActiveWorkbook.Save
      Application.CutCopyMode = False
      End If
  Next i
  End Sub
  </code></pre>