Buck Beasom
asked on
Inserting Excel Formula with Variable from VB2010
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[-intSumRowCounterR ow]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.
Thanks.
.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[-intSumRowCounterR
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.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had to convert the integer to a string, but once I did that, concatenating the string elements as you suggested worked like a charm.
Thanks!