Attila Lazúr
Attila Lazúr

Reputation: 11

Vba if function in formula

I would like to use if function in vba with loop, so a i have a code like below

Worksheets("Teszt_dec").Cells(i, j + oszlop_number + 5).Formula = "=IIf(Teszt!" & Worksheets("Teszt_dec").Cells(i, j + oszlop_number + 5).address(False, False) & "<$F22,1,0)"

and i got these message:

enter image description here

(that means #name error just in hungarian)

And if i select the cells, and press enter the error message suddenly disappear and works fine....

So anyone have any idea how can i solve this problem?

Upvotes: 0

Views: 97

Answers (1)

Vityata
Vityata

Reputation: 43565

Iif is a VBA function. In your case, you are in need of an Excel formula, because you are calling like this:

Worksheets("Teszt_dec").Cells(i, j + oszlop_number + 5).Formula

The Excel formula is =IF.

Thus try with Cells(1,1).Formula = "=IF(condition,true,false)"

Upvotes: 1

Related Questions