0

What is the correct way to code in VBA the below formula? I need to sum 5 columns in a row in the 6th column, and do this for a total of 7 rows.

Range("G21").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-5]:RC[-1])"
Selection.AutoFill Destination:=Range("G21:G27"), Type:=xlFillDefault
sbagnato
  • 603
  • 3
  • 11
  • 35
  • 3
    `ActiveSheet.Range("G21:G27").FormulaR1C1 = "=SUM(RC[-5]:RC[-1])"` – Scott Craner Apr 25 '17 at 14:04
  • Aye did not realize that was simply all i was missing. Thanks! – sbagnato Apr 25 '17 at 14:06
  • 3
    Just to make it explicit, you can replace your three lines of code with @ScottCraner's suggestion. There's [seldom a need to `.Select`/`.Activate` a cell](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) – BruceWayne Apr 25 '17 at 14:13

0 Answers0