I am trying to create a VBA code that inputs the sum function into the cell:
LR = Cells(Rows.Count, 1).End(xlUp).Row
LX = LR - 2
Range("B" & LX).Select
ActiveCell.FormulaR1C1 = "=SUM(R[-LX]C:R[-4]C)"
But when I input LX
into the sum function, it doesn't recognize it as a variable. How can I fix this? Because LX depends on the initial number of rows which can vary.
I don't know how to fix this. I get the run-time error '1004'.