user3603979
user3603979

Reputation: 1

Variables in combination with formulas

In VBA Excel I'm using a combination of variables and a function to be posted in a cell. The variable is containing a value, and the function is a "sum" function.

The variables used is "OB" for the value and "lastrow" for the row number.

When I try to get VBA to write the formula both these are working separately:

ActiveCell.FormulaR1C1 = "=SUM(R[+1]C:R[" & lastrow & "]C)"
ActiveCell.FormulaR1C1 = OB

...but when I try to combine them I get all different types of syntax problem (trying to deduct the sum function from the value in the cell):

ActiveCell.FormulaR1C1 = OB - "=SUM(R[+1]C:R[" & lastrow & "]C)"

Can anyone help me on the syntax to get this to work? Thanks!

Upvotes: 0

Views: 142

Answers (1)

neelsg
neelsg

Reputation: 4842

Try:

ActiveCell.FormulaR1C1 = "=" & OB & "-SUM(R[+1]C:R[" & lastrow & "]C)"

Upvotes: 1

Related Questions