If you want to insert the formula using a macro, you might as well do all the calculations in the macro. It's a matter of personal taste but if I can write a formula once and fill it down, there's not much benefit in composing it in VBA. But the answer to your question is below. However, I notice that you just pulled out the SUMIFS part of the formula I used rather than the entire formula. That will cause every row in column G to have the total minutes for that entire week, instead of just showing it once at the end of the week.
Dim R as Long
' intervening code here....
R = ActiveCell.Row
ActiveCell.Offset(, 5).Formula = "=SUMIFS(C:C,B:B,"">=""&(B" & R & "-MOD(WEEKDAY(B" & R & ")+3,7)),B:B,"<="&(B" & R & "+6-MOD(WEEKDAY(B" & R & ")+3,7)))
I just translated your method exactly to correct it, but I also recommend using a variable of type Range to iterate through the cells, instead of activating each cell. For example:
Dim c As Range
Set c = [B2]
Do While c <> ""
c.Offset(, 5).Formula = ......... ' as above
Set c = c.offset (1, 0)
Loop
This has the advantage of not jumping the active cell around, which is visible to the user unless you disable screen updating. It is also faster, though might not be noticeable for small ranges.
Bookmarks