Error 16, “Expression too complex”, means one statement asked VBA's expression evaluator to juggle more than it can hold: deeply nested function calls, a formula with dozens of terms, or parentheses stacked far beyond readability. The math is usually fine; the shape of the expression is the problem. This is purely a code bug, and the fix is always to break the expression into named steps.
' Too complex as one statement: ' total = (a + b) * (c - d) / (e + f) * (g - h) / (i + j) * ... Dim leftPart As Double, rightPart As Double leftPart = (a + b) * (c - d) / (e + f) rightPart = (g - h) / (i + j) total = leftPart * rightPart
IIf(...) nested inside itself ten deep is a function waiting to be written.SUM over a range; both are simpler for the evaluator and for the next reader.If a modest expression triggers error 16, suspect a recursive user-defined function being evaluated inside it: the expression looks shallow, but the evaluator is also holding the recursion. Test the same formula with the UDF replaced by a literal value to confirm.
Is there a documented complexity limit? Microsoft does not publish an exact count. The limit is reached through combined nesting of operations, calls, and parentheses, which is why splitting the statement into steps reliably clears it.
Why did the expression work in the spreadsheet but not in VBA? The worksheet formula engine and the VBA evaluator are different code with different limits. A formula Excel accepts can still be too complex when pasted into a VBA statement.