# Print Formula in excel with VBA Macro



## kiranmalepat (Dec 16, 2022)

Hi,

I am looking for to print the below formula in excel cell with VBA macro. User should be able to see the formula in excel cell.

=IFERROR(IF(D40<0,-D40,((SUMIF($D$40:$H$40,"<0")*D40/SUMIF($D$40:$H$40,>0)))),0)

Thank you for your help in advance


----------



## rollis13 (Dec 16, 2022)

In my example for cell A1:
if you only need to show the formula in text format use:

```
Range("A1") = "'=IFERROR(IF(D40<0,-D40,((SUMIF($D$40:$H$40,""<0"")*D40/SUMIF($D$40:$H$40,"">0"")))),0)"
```
elsewise, to insert a working formula in the cell, use:

```
Range("A1").Formula = "=IFERROR(IF(D40<0,-D40,((SUMIF($D$40:$H$40,""<0"")*D40/SUMIF($D$40:$H$40,"">0"")))),0)"
```


----------



## kiranmalepat (Dec 16, 2022)

rollis13 said:


> In my example for cell A1:
> if you only need to show the formula in text format use:
> 
> ```
> ...


Thanks a lot. It worked.


----------



## rollis13 (Dec 16, 2022)

Glad having been of some help.
By the way, which one worked ? because I wasn't sure I correctly understood your request .


----------

