Forum Discussion

Naan_Deal's avatar
Naan_Deal
Copper Contributor
Apr 14, 2020
Solved

How to autofill multiple formulas with a range that is down to the last cell of a certain column?

Hi there,   I'm trying to run 5 basic formulas in one macro: ActiveCell.FormulaR1C1 = "=LOOKUP(RC28,Table1)" ActiveCell.FormulaR1C1 = "=WEEKNUM(RC27)" ActiveCell.FormulaR1C1 = "=WEEKDAY(RC27)" ...
  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Apr 15, 2020

    Naan_Deal 

    This piece of code will enter the formulae in AC, AG:AI and AL and copy them down until the last row. Note I changed the formula in AL as the one you provided  (=(ABS)(RC5-RC36)) didn't seem to be correct.

    Sub CopyFormulae()
     
    Dim EndRow As Integer
    EndRow = Sheets("Trade Log").Range("A1").CurrentRegion.Rows.Count
    
    Range("AC4").FormulaR1C1 = "=LOOKUP(RC28,Table1)"
    Range("AC4").Select
    Selection.Copy
    Range("AC5" & ":AC" & EndRow).Select
    ActiveSheet.Paste
    
    Range("AG4").FormulaR1C1 = "=WEEKNUM(RC27)"
    Range("AH4").FormulaR1C1 = "=WEEKDAY(RC27)"
    Range("AI4").FormulaR1C1 = "=IF(RC10>0,""W"",IF(0>RC10,""L"",""F""))"
    Range("AG4:AI4").Select
    Selection.Copy
    Range("AG5" & ":AI" & EndRow).Select
    ActiveSheet.Paste
    
    Range("AL4").FormulaR1C1 = "=ABS(RC5-RC36)"
    Range("AL4").Select
    Selection.Copy
    Range("AL5" & ":AL" & EndRow).Select
    ActiveSheet.Paste
    
    Application.CutCopyMode = False
    
    End Sub

     

Resources