Fix an Application-Defined Error When VBA Writes an Excel Formula
Question details
The user needs to write a nested IF formula to an Excel cell with VBA without triggering an application-defined error.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A VBA macro assigns a formula containing text values and nested IF functions to cell W2.
- Observed behavior
- Excel returns an “Application-defined or object-defined error” when the VBA statement writes the formula.
Check that cell W2 is on the intended worksheet and that columns R, K, and T contain the values the formula should evaluate. If you test the formula manually, use the argument separator required by your Excel regional settings.
Correct the formula string assigned by VBA
Use English function names and comma separators with Range.Formula, and double the quotation marks around text values in the VBA string.
In Excel, open Developer > Visual Basic and find the procedure that writes the formula to W2.
Replace the failing statement with: Range("W2").Formula = "=IF(R2=""Completed"",IF(K2<=T2,""On Time"",""Overdue""),""Not Finished"")"
Run the procedure and select W2 to check the result. The formula returns “On Time” or “Overdue” when R2 is “Completed”; otherwise, it returns “Not Finished.”

Record a macro to inspect Excel's formula syntax
Use this method if you are unsure how to express a working worksheet formula in VBA.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. Its Excel format support makes it easy to move everyday spreadsheet work between Office applications, though it does not fix Microsoft Excel VBA errors.

Frequently Asked Questions
Why does Range.Formula use commas when my worksheet uses semicolons?
Range.Formula expects standard English formula syntax with commas. Manual formula entry may use semicolons depending on your regional settings.
How do I put text in a formula string in VBA?
Double each quotation mark that should appear inside the formula. For example, write ""Completed"" inside the VBA string to pass "Completed" to Excel.
Can I use my local formula syntax in VBA?
You can use Range.FormulaLocal when supplying a formula in the user's local language and format. Its function names and separators depend on the Excel installation.
What if the corrected formula still writes to the wrong sheet?
Qualify the range with the intended worksheet, for example Worksheets("Sheet1").Range("W2").Formula, and replace Sheet1 with the actual sheet name.




