title: Excel VBA: AutoFill Multiple Cells with Formulas
body: <p>I have big amount of data that I collected from different files. In this main workbook, I have different types of formulas for every cells. In range A to F is where the data from other files are collected. In range H to AC, I have the formula that I auto fill by dragging it down  manually every time new data is entered. The code below is what I used and it only have 6 different formulas that I want to auto fill. </p>
  
  <pre><code>Application.ScreenUpdating = False
  
  lastRow = Range("B" &amp; Rows.Count).End(xlUp).Row
  Range("D2").Formula = "=$L$1/$L$2"
  Range("D2").AutoFill Destination:=Range("D2:D" &amp; lastRow)
  
  Range("E2").Formula = "=$B2/2116"
  Range("E2").AutoFill Destination:=Range("E2:E" &amp; lastRow)
  
  Range("F2").Formula = "=$D$2+(3*SQRT(($D$2*(1-$D$2))/2116))"
  Range("F2").AutoFill Destination:=Range("F2:F" &amp; lastRow)
  
  Range("G2").Formula = "=$D$2-(3*SQRT(($D$2*(1-$D$2))/2116))"
  Range("G2").AutoFill Destination:=Range("G2:G" &amp; lastRow)
  
  Range("H2").Formula = "=IF($E2&gt;=$F2,$E2,NA())"
  Range("H2").AutoFill Destination:=Range("H2:H" &amp; lastRow)
  
  Range("I2").Formula = "=IF($E2&lt;=$G2,$E2,NA())"
  Range("I2").AutoFill Destination:=Range("I2:I" &amp; lastRow)
  ActiveSheet.AutoFilterMode = False
  
  Application.ScreenUpdating = True
  </code></pre>
  
  <p>However, in the main workbook there is like 15 different formulas that I want it to auto fill every time new data enters. I have multiple main workbook, and the formula is not constant. Inserting the code above for every formula is a pain. Is there a way that can make the program to drag it down automatically? In the main workbook, I have the formulas written out already. I tried many different codes to make it auto fill, but so far the one above is the only one that working without giving me errors. I tried using something like this or similar version to this one, but none is working:</p>
  
  <pre><code>With wbList.Sheets("Attribute - 10 mil stop")
      lastRow = Worksheets(ActiveSheet.Name).Range("B2").Rows.Count
      'Worksheets(ActiveSheet.Name).Range(Selection, Selection.End(xlDown)).Select
      Worksheets(ActiveSheet.Name).Range("D2:I2").Select
      Selection.AutoFill Destination:=Range("D2:I" &amp; Range("B2" &amp; Rows.Count).End(xlDown).Row)
  End With
  </code></pre>
  
  <p>I messed around with the code so much. I don't even know if it's suppose to be like that. Thank you for helping!</p>