0

I'm trying to add a formula in cell AE2 to my worksheet with the help of VBA Excel. However when I paste the formula in VBA and hit enter on the line I get the following error:

Compile error: Expected: end of statement

This is the piece of code and formula I'm trying to use:

    Range("AE2").Select
ActiveCell.FormulaR1C1 = "=IF(OR(D2="ECHARGEUR2",D2="ECHARGEUR3",D2="ECHARGEUR1",D2="ECHARGERO2",D2="ECARD001",D2="ECARD002",D2="ECARD003"),L2,1*MID(D2,MATCH(TRUE,ISNUMBER(1*MID(D2,ROW($1:$8),1)),0),COUNT(1*MID(D2,ROW($1:$8),1))))"

Can someone see what I'm missing here?

Tom
  • 127
  • 1
  • 13
  • 2
    In `"=IF(OR(D2="` the second `"` closes the quotes, so the subsequent parts just causes an error. You need to escape the quotation mark characters. See https://stackoverflow.com/questions/9024724/how-do-i-put-double-quotes-in-a-string-in-vba – qrsngky Nov 10 '22 at 06:43
  • 2
    `"=IF(OR(D2=""ECHARGEUR2"",D2=""ECHARGEUR3"", ...` – Tim Williams Nov 10 '22 at 06:49

0 Answers0