title: Populating template from 2 worksheets; data from 2nd worksheet not copying to correct line after first completed template
body: <p>I am creating an individual worksheet for each employee based on a template which is populated from two worksheets. I can get the Employee_Data to populate correctly. (Thanks to assistance from Tim Williams.)  However, when copying the JobHist_DataWorking data only the first completed template is on the correct line; subsequent worksheets are populated further down.  The job history information should begin pasting to line 19 for the first job record.</p>
  
  <p>Being a novice coder, I played with the code and have managed to get the last employee to populate on line 40 rather than line 260 as my earlier attempts netted. However, it needs to be on line 19.  I looked at the Do While/Until Loop but could not get the placements in my current code to run. Below is my code as it currently works but not correctly.</p>
  
  <p>EDIT: Code has been updated as suggested.</p>
  
  <p>EDIT #2: Code has been updated to reflect it working correctly thanks to help of Darrell H.</p>
  
  <pre><code>Option Explicit
  
  Sub NewSheets()
      Dim i As Integer
      Dim j As Integer
      Dim x As Integer
  
      Dim ws As Worksheet, wb As Workbook
      Dim sh As Worksheet, wsCopy As Worksheet, v
      Dim sht As Worksheet
  
      Set wb = ActiveWorkbook
      Set ws = wb.Sheets("Template")
      Set sh = wb.Sheets("Employee_Data")
      Set sht = wb.Sheets("JobHist_DataWorking")
  
      x = 19
  
      For i = 2 To sh.Range("B" &amp; sh.Rows.Count).End(xlUp).Row
  
          ws.Copy After:=wb.Sheets(Sheets.Count)
          Set wsCopy = wb.Sheets(wb.Sheets.Count)
  
          wsCopy.Name = sh.Range("F" &amp; i).Value
          wsCopy.Range("C1").Value = sh.Range("A" &amp; i).Value
          wsCopy.Range("C2").Value = sh.Range("G" &amp; i).Value
          wsCopy.Range("C3").Value = sh.Range("H" &amp; i).Value
          wsCopy.Range("C4").Value = sh.Range("I" &amp; i).Value
          wsCopy.Range("C5").Value = sh.Range("J" &amp; i).Value
          wsCopy.Range("C6").Value = sh.Range("S" &amp; i).Value
          wsCopy.Range("C7").Value = sh.Range("V" &amp; i).Value
          wsCopy.Range("C8").Value = sh.Range("W" &amp; i).Value
          wsCopy.Range("C9").Value = sh.Range("X" &amp; i).Value
          wsCopy.Range("C11").Value = sh.Range("L" &amp; i).Value
          wsCopy.Range("C12").Value = sh.Range("AH" &amp; i).Value
           v = sh.Range("AJ" &amp; i).Value
          If Len(v) &gt; 0 Then wsCopy.Range("C13").Value = v
          wsCopy.Range("C14").Value = sh.Range("AM" &amp; i).Value
          wsCopy.Range("C15").Value = sh.Range("AP" &amp; i).Value
          wsCopy.Range("C16").Value = sh.Range("AQ" &amp; i).Value
          wsCopy.Range("H1").Value = sh.Range("F" &amp; i).Value
          wsCopy.Range("H3").Value = sh.Range("K" &amp; i).Value
          wsCopy.Range("N1").Value = sh.Range("C" &amp; i).Value
          wsCopy.Range("N11").Value = sh.Range("N" &amp; i).Value
  
  
            For j = 2 To sht.Range("A" &amp; Rows.Count).End(xlUp).Row
                 With Worksheets("JobHist_DataWorking")
                      If Not sht.Range("A" &amp; j).Value = wsCopy.Range("C1") Then
                          x = 19
                          Else
                              sht.Range(.Cells(j, 3), .Cells(j, 4)).Copy
                                 wsCopy.Range(wsCopy.Cells(x, 1), wsCopy.Cells(x, 2)).PasteSpecial xlPasteValues
                              sht.Range(.Cells(j, 6), .Cells(j, 8)).Copy
                                 wsCopy.Range(wsCopy.Cells(x, 3), wsCopy.Cells(x, 5)).PasteSpecial xlPasteValues
                              sht.Range(.Cells(j, 9), .Cells(j, 12)).Copy
                                wsCopy.Range(wsCopy.Cells(x, 7), wsCopy.Cells(x, 10)).PasteSpecial xlPasteValues
                              Application.CutCopyMode = False
                       x = x + 1
                      End If
                  End With
                Next j
  
       Next i
  
  End Sub
  </code></pre>
  
  <p>The first employee has three job records which are currently populating on lines 19, 20 and 21 as expected. The second employee also has three job records, but they are populating on lines 22, 23 and 24. The third employee has two job records which are populating on lines 25 and 26.  This progression down the template continues such that the 10th and 11th employees who have only one job record each are populating on lines 39 and 40 respectively.</p>
  
  <p>The job history for each employee should begin on line 19. Thank you for your help.</p>