I have a macro for which I would like that it calculates me the sum of all my value contains in column B (from cell B2 to last row). I configured my macro in order that it selects the first cell empty just under the lastrow
of my column B (until the penultimate line of my VBA code, my macro works perfectly, I tested it).
My problem is that the last line of my VBA code does not work, apparently the last line of my VBA code: ActiveCell.Formula "=SUM(B2:B" & lastrow & ")"
is not correct and because of this line, the macro returns me the error message
Compile error: invalid use or property.
If someone could help me, that would be great. Thanks a lot in advance. Xavi
Sub Process()
Dim lastrow As Long
lastrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
ActiveSheet.Cells(ActiveSheet.Rows.Count,Selection.Column).End(xlUp).Select
ActiveCell.Offset(1, 1).Select
ActiveCell.Formula "=SUM(B2:B" & lastrow & ")"
End Sub