VBA & Macro Problems

Fix an Application-Defined Error When VBA Writes an Excel Formula

Nimra MalikNimra Malik Nov 13, 2026 868 views

Question details

The user needs to write a nested IF formula to an Excel cell with VBA without triggering an application-defined error.

Fix an Application-Defined Error When VBA Writes an Excel Formula
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA code

In Excel, open Developer > Visual Basic and find the procedure that writes the formula to W2.

2
Replace the formula assignment

Replace the failing statement with: Range("W2").Formula = "=IF(R2=""Completed"",IF(K2<=T2,""On Time"",""Overdue""),""Not Finished"")"

3
Run and check the macro

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.”

Correct the formula string assigned by VBA
Regional separators: Range.Formula uses the standard English formula syntax with commas, even if your worksheet uses semicolons for local formula entry. You do not need to change your regional settings.
Free Microsoft Office alternative

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.

Open and edit spreadsheets with nested IF formulas in WPS SpreadsheetCompatible with Microsoft Excel formats, including XLSX and XLSFamiliar spreadsheet interface for an easier transition from Microsoft OfficeFree and lightweight for everyday document work
microsoft office alternative - wps office

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.