Reputation: 681
Ok, I have used a formula that was suggested that works well, should work without an issue but now I am getting this error:
Expected End of Statement
Here is the formula
Range("B4").FormulaR1C1 = "=IF(RC[-1]="T",VLOOKUP(RC[7],treatlookup,11,FALSE),VLOOKUP(RC[7],itemlookup,22,FALSE))"
Not sure what is going on, why it is happening. Any suggestions.
Thanks,
Upvotes: 2
Views: 3310
Reputation: 125651
Escape the embedded double-quotes ("T"
) by doubling them (""T""
):
Range("B4").FormulaR1C1 = "=IF(RC[-1]=""T"",VLOOKUP(RC[7],treatlookup,11,FALSE),VLOOKUP(RC[7],itemlookup,22,FALSE))"
^^^
|
Here
Excel is trying to pair the opening quote at "=IF
with the next double-quote it finds, which is at "T"
, and that portion ("=IF(RC[-1]="
) isn't a valid statement. Doubling them tells Excel to consider them separately, allowing them to be embedded in the formula correctly.
(The error is highlighted for you when you get the message, if you look at the code it's indicating; that's how I spotted it.)
Upvotes: 2