0

How can I write the formula in the active cell? The active cell already has the formula: =+sum(i10:i195)-i197

I want to change this active cell formula to = sum(i10:I195)-i197+i196

I have the VBA code:

WorkSheets(1).range(“i10”).End(xlDown). Select

Selection. FormulaR1C1 = “selectiin -+ selection. Offset(-3,0)

But there’s no response. Does anyone have a suggestion on how to solve this?

Toddleson
  • 4,321
  • 1
  • 6
  • 26
Joe Chan
  • 21
  • 5
  • Can you explain what it is you are trying to do. I can't tell from your description above. Maybe edit the post to add additional information. Also you should review this post on how to avoid using `.Select` https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba – Glenn G Oct 19 '22 at 14:04
  • Easier to understand your code if you could copy and paste it - guessing you're not leaving spaces in the line or spelling `“selectiin` incorrectly. – Darren Bartrup-Cook Oct 19 '22 at 14:31
  • Thx Glenn. My question is not clear. I will improve it next time. Thx Darren. I will take care my spelling in next time. – Joe Chan Oct 20 '22 at 03:33

1 Answers1

2

You can retrieve the ActiveCell's formula by using its .Formula property. Look in ActiveCell.Formula to see what its current formula is. Then, if you want to append something onto it, you would just do

ActiveCell.Formula = ActiveCell.Formula & "+I196"

If you want this to be an Offset of the ActiveCell, you need to use the Address property like:

ActiveCell.Formula = ActiveCell.Formula & "+" & ActiveCell.Offset(-3, 0).Address

Toddleson
  • 4,321
  • 1
  • 6
  • 26