Hi, I totally agree with Saboh. But if you still want to use VBA, here is some starting points :
Last row based on column A :
LR = Sheets("SheetName").Range("A" & Rows.Count).End(xlUp).Row
Writing formula with VBA :
Sheets("SheetName").Range("A1").Formula = "=SUM(B1:B" & LR & ")"
You can also use generic formulas like =SUM(B:B), but those ones use quite more ressources.