title: Auto-filing a formula to the last row of a column
body: <p>I need to constantly start at cell R2 and auto-fill a formula down to the last row of column R. However, the number of rows is constantly changing so I need to write a macro that finds the last row and stops there.  My code, as it stands right now, will auto-fill column R to the end of the worksheet (not to the row where my data stops).  How do I get the auto-fill to stop at the correct row where there is no longer any data? </p>
  
  <pre><code>Sub InvoicePrice()
  
  Dim Lastrow As Long
  
  Lastrow = Range("P" &amp; Rows.Count).End(xlDown).Row
  
  Range("R2").Select
      ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-4]"
      Selection.AutoFill Destination:=Range("R2:R" &amp; Lastrow)
  
  
  
  End Sub
  </code></pre>