# VBA code to insert formula -



## Josu (Dec 16, 2022)

I am having issue to make macro to insert formula. In other excel spreadsheet similar macro was working fine, but here I am having issues.
I want to insert formula to A25 and basically drag down until A75...  Formula is =IF(OR(Data!C2=""),"",Data!C2)
I tried couple of options, but no luck. I have a feeling this is due to IF in formula
Can you help me please?

```
Sub RunFormulaStores() 'inserting formula for workgroup
'Dim last_row As Long
Dim iRange As Range
Set iRange = Range("A25:A75")
'last_row = Cells(Rows.Count, 4).End(xlUp).Row
iRange.Formula = "=IF(OR(Data!C2=""""),"""",Data!C2))"
' for every " in excel formula need to add, also in ran-ge there is drag down until last row
Range("A25").AutoFill Destination:=Range("A25:A75") '& last_row)
End Sub
```
Or 

```
Sub x()
Dim ws As Worksheet
Set ws = Sheets("Settings")
ws.Activate
Range("A24").Formula = "=IF(OR(Data!C2=""""),"""",Data!C2))"
End Sub
```


----------



## breynolds0431 (Dec 16, 2022)

Hi. You shouldn't need the OR part in the formula as you only have one condition to test (i.e.; if Data!C2=""). Either that or you're missing the other condition for the OR statement. The below should work for you if there's only one condition in the IF statement. 


```
Sub fillformula()

Range("A24:A75").Formula = "=IF(Data!C2="""",1,Data!C2)"

End Sub
```


----------

