Code Assistance

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Code Assistance

Post by jstevens »

I am having a challenge assigning a formula to a cell via VBA. The challenge is that "E16" is blank and is causing the issue. I'm being returned a run-time error 1004. I know the formula works because I can enter it in preceeded with an apostrophe, remove the appostrophe and get this message. After selecting "yes" it works.
untitled.png
The line of code is as follows:
Sheets("T&E Input").Range("F16:F16").Formula = "=IF(ISTEXT(E16),VLOOKUP(E16,R_TE_Table,2,FALSE),"")"

Thanks for your suggestions,
John
You do not have the required permissions to view the files attached to this post.
Regards,
John

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Code Assistance

Post by HansV »

You must double the quotes within the formula:

Sheets("T&E Input").Range("F16:F16").Formula = "=IF(ISTEXT(E16),VLOOKUP(E16,R_TE_Table,2,FALSE),"""")"
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Code Assistance

Post by jstevens »

Hans,

It worked perfectly.

Thanks,
John
Regards,
John