Forum Discussion
Naan_Deal
Apr 14, 2020Copper Contributor
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)" ...
- Apr 15, 2020
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
Riny_van_Eekelen
Apr 15, 2020Platinum Contributor
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
Naan_Deal
Apr 15, 2020Copper Contributor
Riny_van_Eekelen I cannot thank you enough Riny. I'm really really grateful. Thank you so much!
- Riny_van_EekelenApr 15, 2020Platinum Contributor
Naan_Deal Most welcome!