Link to home
Start Free TrialLog in
Avatar of Buck Beasom
Buck BeasomFlag for United States of America

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[-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.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of VipulKadia
VipulKadia
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Buck Beasom

ASKER

Perfectamundo!

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!