danomaniac
Programmer
Hey Everyone,
I'm trying to insert a formla via code. I have a database query that returns some data and then my code deletes rows based on user selected criteria. This results in an unknown number of rows each time. I can count the resulting rows via code, but can't figure out how to transfer that variable data into my FormulaR1C1 statement. This is what I have, and obviously, the variable won't work in the statement, but that's where I need it. Any ideas? Thanks very much for any help.
Cells(2, 1).Activate
Selection.End(xlDown).Activate
lastrow = ActiveCell.Row
Cells(lastrow + 2, 12).Activate
ActiveCell.FormulaR1C1 = "=(SUM(R[newlastrow]C:R[-2]C))"
I'm trying to insert a formla via code. I have a database query that returns some data and then my code deletes rows based on user selected criteria. This results in an unknown number of rows each time. I can count the resulting rows via code, but can't figure out how to transfer that variable data into my FormulaR1C1 statement. This is what I have, and obviously, the variable won't work in the statement, but that's where I need it. Any ideas? Thanks very much for any help.
Cells(2, 1).Activate
Selection.End(xlDown).Activate
lastrow = ActiveCell.Row
Cells(lastrow + 2, 12).Activate
ActiveCell.FormulaR1C1 = "=(SUM(R[newlastrow]C:R[-2]C))"