title: How can I autofill to last row of data using VBA?
body: <p>I select two columns and add a formula in them. Then I wish to autofill to the last row. However, every week the same dataset gets additional rows and I do not know how to autofill it so that it goes to the last row. Currently I have it so that it autofills to the 5000th row but however that creates anomalies. How can I make it so that the formula I have gets autofilled to the last row?</p>
  
  <pre><code>Range("BG1").Select
  ActiveCell.FormulaR1C1 = "Total_Time_Spent (Dev)"
  Range("BG2").Select
  Application.WindowState = xlNormal
  ActiveCell.FormulaR1C1 = _
      "=IF(RC[-47]=R[-1]C[-47],SUMIF(C[-47], RC[-47], C[-20]), SUMIF(C[-47], RC[-47], C[-20]))"
  Range("BG2").Select
  Selection.AutoFill Destination:=Range("BG2:BG5000")
  Range("BG2:BG2108").Select
  Range("BH2").Select
  ActiveCell.FormulaR1C1 = _
      "=IF(RC[-48]=R[-1]C[-48],SUMIF(C[-48], RC[-48], C[-20]),SUMIF(C[-48], RC[-48], C[-20]))"
  Range("BH2").Select
  Selection.AutoFill Destination:=Range("BH2:BH5000")
  Range("BH2:BH2108").Select
  Range("BH1").Select
  ActiveCell.FormulaR1C1 = "Total_Time_Spent (UAT)"
  </code></pre>