If your starting cell is G2, then you can replace the first
ActiveCell.Offset with "G2" - it was only moving you one to the right of
your search-down cell anyway,
The second ActiveCell would be changed to a Range("F2") because it needs to
move down before offsetting to the right for the "G" column.
Re terminology ... you had it right in the first place. My question was
probably a bit cryptic. The formula is the text that you put in the cell.
Usually, the term is only used when the text starts with an "=" sign
(although technically anything entered in a cell is its formula). So it IS
a formula you want to copy.
My main interest in your formula was to find out if it had relative cell
references in it, that would change as you copied the cell - i.e. your F2.
And you are using a function inside the formula (i.e. SumIf).
As luck would have it (or is it Murphy's law?) you have hit on a column that
doesn't pass nicely through R1C1 notation without change - i.e. "C". So if
you just make the FormulaR1C1 into
"=SUMIF(C:C,RC[-1],D:D)"
then the D:D will be passed through fine. The RC[-1] will offset correctly
one column to the left. But the C:C will be treated as a reference to the
column the formula is in (i.e. G).
Because of this, you need to state your C column reference in R1C1 notation.
For completeness, it would be nice to do the D column the same way. So the
end result is a single VBA statement again:
Range("G2", Range("F2").End(xlDown).Offset(0, 1)).FormulaR1C1 =
"=SUMIF(C3:C3,RC[-1],C4:C4)"
The formula that ends up in G5 is
=SUMIF($C:$C,F5,$D:$D)
and similarly for the other G cells that have corresponding F cells.