Inserting Excel Formula with Variable from VB2010
Posted on 2011-10-20
I have successfully used this code:
.Cells(intR, intC).FormulaR1C1 = "=Sum(R[-2]C:R[-1]c)" to put a Sum formula into and Worksheet.
Now I am trying to use this code:
.Cells(intR, intC).FormulaR1C1 = "=Sum(R[-intSumRowCounterRow]C:R[-1]c)"
The difference in the situations is that in the first, I KNOW I always will want to sum two rows. In the second case, the length of the column I want to sum varies, and is being counted in the variable "intSumRowCounterRow" as rows are added. The error that it is throwing is:
"EXCEPTION from HRESULT: 0x800AO3EC".
Any advice on how to insert the formula would be appreciated.