title: Excel VBA Copy and paste range
body: <p>In my sheet I calculate the prime factors for a number, the range is from E6 onwards. I have the following line of code to determine the number of rows.</p>
  
  <pre><code>rCount = Application.WorksheetFunction.CountA(Range("E:E")) - 1
  </code></pre>
  
  <p>The minus 1 is to exclude the header and get only the range containing numbers. I have also set the range and copied as follows:</p>
  
  <pre><code>Set rgCopy = Range("E6", Selection.End(xlDown))
      Selection.Copy
  </code></pre>
  
  <p>However, when I try to paste this in a cell it gives me the following error:</p>
  
  <pre><code>Run-time error '1004':
  Method 'Range' of object'_Global' failed
  </code></pre>
  
  <p>Here's the coding I have so far</p>
  
  <pre><code>Dim rgCopy As Range
      Dim rCount As Integer
  
      Set rgCopy = Range("E6", Selection.End(xlDown))
      Selection.Copy
      rCount = Application.WorksheetFunction.CountA(Range("E:E")) - 1
      lastrow = Cells(Rows.Count, 4).End(xlUp).Row
  
      Range("E6:" &amp; Selection.End(xlDown)).Copy Destination:=Range("D" &amp; lastrow + 5)
  </code></pre>
  
  <p>Any assistance would be appreciated.</p>