Using Variables in ActiveCell.Formula

  • Thread starter dustinbrearton via OfficeKB.com
  • Start date
D

dustinbrearton via OfficeKB.com

I am trying to use the below code to insert
"=SUM(D2:D3)"


LastStop = 1
X = 4

StartCell = "D" & LastStop + 1
EndCell = "D" & X - 1
ActiveCell.FormulaR1C1 = "=Sum(" & StartCell & ":" & EndCell & ")"

The result of the activecell.formula line is "=Sum('D2':'D3')"

For ease of explanation I have set LastStop and X to certain numbers. In my
code these two variables change based on where the set ends.

Where have I gone wrong in the ActiveCell.Formula line? How do I get rid of
the ' so that the formula will actually work?
 
R

Rick Rothstein

Don't use FormulaR1C1 for a formula using normal ranges, use just Formula...

ActiveCell.Formula = "=Sum(" & StartCell & ":" & EndCell & ")"
 
D

dustinbrearton via OfficeKB.com

Do'h. I did not even notice that was on there. Thanks.

Rick said:
Don't use FormulaR1C1 for a formula using normal ranges, use just Formula...

ActiveCell.Formula = "=Sum(" & StartCell & ":" & EndCell & ")"
I am trying to use the below code to insert
"=SUM(D2:D3)"
[quoted text clipped - 15 lines]
of
the ' so that the formula will actually work?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top