If you want to fill a range of cells 'en-masse' this will be ok, and fill all the cells with the correct formula

Code: Select all

`Range("D2:D10").Formula = "=IF(AND(A2=1,B2=1,C2=1),1,0)"`

If you need to step through them and only fill every other cell, this will fail because it will always reference the original cells, ie, A2,B2,C2

Code: Select all

```
For x = 2 To 10 Step 2
Cells(x, 4).Formula = "=IF(AND(A2=1,B2=1,C2=1),1,0)"
Next
```

You have to use the R1C1 notation to get the correct formulas in each cell: (Just type your formula in as normal, then switch to R1C1 and copy the formula from the formula bar into your code).

Code: Select all

```
For x = 2 To 10 Step 2
Cells(x, 4).FormulaR1C1 = "=IF(AND(RC[-3]=1,RC[-2]=1,RC[-1]=1),1,0)"
Next
```

The 'expected end of statement' probably appears because you could have something like:

Code: Select all

`Range("D2").Formula = "=IF(A2=1,"Back","")"`

But if you have anything in quotation marks in the formula, they themselves have to be within quotation marks (real pain)

Code: Select all

`Range("D2").Formula = "=IF(A2=1,""Back"","""")"`