-1

I'm getting a syntax error at the below code, Please do help me soon

Thanks

Set rng = Range("AM4:AM" & Lastrow)
rng.Formula = "=IF(P4="Y",1,0)"  //I need to execute this statement// 

I have attached the screen shot of the error message with the whole code

Tim Williams
  • 154,628
  • 8
  • 97
  • 125

1 Answers1

2

Instead, try using two double-quotes around the Y:

rng.Formula = "=IF(P4=""Y"",1,0)"

If you want to include a (double) quote inside a string, you need to do this, otherwise it looks like you are ending the string, then VBA gets confused when it gets to Y

Ernie Thomason
  • 1,579
  • 17
  • 20