Trouble with IF statement in VBA

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

I am having trouble in VBA for an Excel 2003 project. The following works fine:
Range("AccountNumber").FormulaR1C1 = "=VLOOKUP(Template,TemplateDetails,4,FALSE)"

The following gives me a run time error 1004 Application-definded or object-defined error:
Range("AccountNumber").FormulaR1C1 = "=IF(ISNA(VLOOKUP(Template,TemplateDetails,4,FALSE)),"", _
VLOOKUP(Template,TemplateDetails,4,FALSE))"

The formula works fine when used in a cell on a worksheet. When I put it into VBA, I get the error. I am guessing the double quotes in the formula are the root of the problem. Do I put quotes around the quotes?

Best regards,

GL
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
TIP OF THE DAY: Whenever I create a formula that will be written into cells via VBA, I get the right VBA syntax quickly by just typing the formula out first in the first target cell while the macro recorder is running. That will give you the correct base code...easy to tweak from there.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top