title: Macro to Auto Fill Down to last adjacent cell
body: <p>I am trying to use macro recorder in Excel to record a macro to fill down a column of cells, however because the fill down each time is a different number of cells it either fills down to short or too long and this seems to be because the macro identifies the cell range and its fixed.</p>
  
  <p>Is there anyway that I can get it to fill down to the last populated neighbouring cell. E.g. AutoFill down column E until it reaches the last populated row in column D. I have looked at some examples on here but the code all looks very different so not sure if it can be done with macro recorder or I have to get someone to write some code or is it something that has to be done manually?</p>
  
  <p>This is the code that I have in the macro.</p>
  
  <pre><code>ActiveCell.FormulaR1C1 = _
          "=IF(MONTH(RC[-1])&gt;3,"" ""&amp;YEAR(RC[-1])&amp;""-""&amp;RIGHT(YEAR(RC[-1])+1,2),"" ""&amp;YEAR(RC[-1])-1&amp;""-""&amp;RIGHT(YEAR(RC[-1]),2))"
      Selection.AutoFill Destination:=Range("E2:E1344")
      'Selection.AutoFill Destination:=Range("E2:E1344")
      Range("E2:E1344").Select
  </code></pre>
  
  <p>If anyone can help i'd be extremely grateful</p>