title: Run-time error '1004' when trying to copy a range (Excel VBA)
body: <p>I am trying to copy a range of cells for which I don't know the last row and column (though I can easily get to those using variables).  Unfortunately though, the way I am trying to reference a range is giving me a run-time error 1004 (Application-defined or object-defined error) when I use variables, and I can't figure out why.  Below is a sample of the code:</p>
  
  <pre><code>Dim wkbk As Workbook
  Dim copy_rng As Range
  ...
  Set copy_rng = wkbk.Worksheets("Payable").Range("A1:Y3500")
  Set copy_rng = wkbk.Worksheets("Payable").Range(Cells(1, 1), Cells(last_row_pay, last_col_pay))
  </code></pre>
  
  <p>The first Set statement is simply an example, and it works fine (so I know wkbk is properly defined and it's finding the "Payable" worksheet).  Does anybody know why the second Set statement would not work?  Is there a syntax issue?  (During debug, if I hover over the last_row_pay and last_col_pay variables, I can see valid values--1533 and 25 respectively.)  Thanks for any help.</p>