title: Worksheets.Count in VBA is returning the wrong number of pages
body: <p>I have a data workbook with a number of worksheets (3 to be exact). I would like to copy the data from each worksheet and add them all in one worksheet (append one before the other) in a second workbook. All the worksheets have the same format and same columns, so I can condidently do it without worrying about data consistency. The problem is that the for loop I am using runs the code 21 times even though I only have 3 worksheets, and no copying and pasting takes place. I used MsgBox to debug. The following is the code, written in VBA editor of Excel 2013 on a Windows OS:</p>
  
  <pre><code>Sub compileData()
      ' compile all the data in one worksheet
  
      ' defining variables
      Dim i As Integer
  
      ' copy the headers
      Windows("source_file.xlsx").Activate
      Sheets(1).Activate
      Range("A3:K3").Select
      Selection.Copy
      Windows("target_file.xlsx").Activate
      Sheets(1).Activate
      Range("A1").Select
      ActiveSheet.Paste
      ' So far, so good! The header was copied &amp; pasted with no problem.
  
      For i = 1 To Workbooks("source_file.xlsx").Worksheets.Count
  
          ' copy data from source worksheet
          Windows("source_file.xlsx").Activate
          Sheets(i).Activate
          Range("A4:K4").End(xlDown).Select
          Selection.Copy
  
          ' paste data
          Windows("target_file.xlsx").Activate
          Sheets(1).Activate
          Range("A2").End(xlDown).Offset(RowOffset:=1).Select
          ActiveSheet.Paste
  
      Next i
  
      MsgBox i      ' this returns 21 while source_file.xlsx has only 3 worksheets
  
  End Sub
  </code></pre>