# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  how to insert formula in VBA

## associates

Hi,

I'm having problem with inserting formula into cells in VBA. I was trying to get some idea by using macro recording. 

I got the following 
ActiveCell.FormulaR1C1 = "=R[-1]C[-1]+RC[-1]"

but i don't understand this. 

I suppose what i'm trying to do is be able to insert the formula in some cells.

for example: =B5-A5 -> inserted into cell "C5"

Thank you in advance

----------


## VBA Noob

Hi,

This is OTT but give you an idea on setting ranges etc




```
Please Login or Register  to view this content.
```


VBA Noob

----------


## Bryan Hessey

> Hi,
> 
> I'm having problem with inserting formula into cells in VBA. I was trying to get some idea by using macro recording. 
> 
> I got the following 
> ActiveCell.FormulaR1C1 = "=R[-1]C[-1]+RC[-1]"
> 
> but i don't understand this. 
> 
> ...



Hi,

just use the obvious,

 Range("C5").Fornula = "=B5-A5"

or

 Range("C5:C25").Formula = "=B5-A5" 

or

 Range("C5:C25").Formula = "=B$5-A5" 


hth
---

----------


## titubd

can someone help me with this code, please




```
Please Login or Register  to view this content.
```

----------


## arlu1201

titubd,

Welcome to the forum.

Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do.  Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.

Also,

I have added *code tags* to your post.  As per forum rule 3, you need to use them whenever you put any code in your post.  Please add them in future.  If you need more information on how to use them, check my signature below this post.

----------


## mahaveersomani

paste the following code in which sheet you want to get your data.




```
Please Login or Register  to view this content.
```


Regards
CA Mahaveer Somani

----------


## arlu1201

Mahaveer,

Welcome to the forum.

I have added *code tags* to your post.  As per forum rule 3, you need to use them whenever you put any code in your post.  Please add them in future.  If you need more information on how to use them, check my signature below this post.

----------

