title: Why does my VBA code not copy and paste when sheet is not active?
body: <p>After much Googling and searching the net I have been unable to determine what is going wrong with my code.</p>
  
  <p>If I run the following code on the XXXXX Sheet, the last row is copied and pasted in the row below with no issues:</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
  Dim EndRow
  
  EndRow = Range("A65536").End(xlUp).Row
  
  Range("A" &amp; EndRow, "M" &amp; EndRow).Copy Range("A" &amp; EndRow + 1, "M" &amp; EndRow + 1)
  
  End Sub
  </code></pre>
  
  <p>However, I need to run the code from a different tab and have the following formula which does not work. The button is clicked and nothing is copy and pasted:</p>
  
  <pre><code>Private Sub CommandButton2_Click()
  
  Dim EndRow
  EndRow = Sheets("XXXXX").Range("A65536").End(xlUp).Row
  
  With Sheets("XXXXX")
  
  .Range("A" &amp; EndRow, "M" &amp; EndRow).Copy Range("A" &amp; EndRow + 1, "M" &amp; EndRow + 1)
  
  End With
  End Sub
  </code></pre>
  
  <p></p>
  
  <p>Where am I going wrong???</p>
  
  <p>Thanks for your help.</p>