• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

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.
0
Buck_Beasom
Asked:
Buck_Beasom
1 Solution
 
VipulKadiaCommented:
Try this one :
.Cells(intR, intC).FormulaR1C1 = "=Sum(R[-" & intSumRowCounterRow & "]C:R[-1]c)"
0
 
Buck_BeasomDatabase DesignerAuthor Commented:
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!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now