title: Macro crashes after running. Anyway to make code/formula more efficient?
body: <p>I have about 250,000 rows and the following code takes really long to process. Is there a way to shorten the formula or create custom functions so as to make it run quicker and more efficiently?</p>
  
  <pre><code>Sub test123()
  
  
  Dim lastrow, lastrowAI As Long
  
  
  lastrow = Cells(Rows.Count, "C").End(xlUp).Row
  lastrowAI = Cells(Rows.Count, "AI").End(xlUp).Row
  
  
  For i = lastrowAI + 1 To lastrow
  
  Range("AI" &amp; i).Formula = "=IF(F" &amp; i &amp; "&gt;=EDATE(MAX($F$11:$F$1048576),-23),""Latest Months"",""Consol. Years"")"
  
  
  Next
  
  
  End Sub
  </code></pre>