What does -- do in Excel formulas?

lucks picture lucks · Jul 20, 2010 · Viewed 41.5k times · Source

Trying to decipher some Excel formulas and I see some stuff like SUMPRODUCT(--Left(...)...)

What is the -- doing? Naturally seems like decrementing to me but couldn't find any documentation on it.

Answer

The double-dash is known as a double unary operator.

Try this link: Why use -- in SUMPRODUCT formulae

Specifically:

SUMPRODUCT() ignores non-numeric entries. A comparison returns a boolean (TRUE/FALSE) value, which is non-numeric. XL automatically coerces boolean values to numeric values (1/0, respectively) in arithmetic operations (e.g., TRUE + 0 = 1).

The most efficient way to coerce the value is first to apply the unary minus operator, coercing TRUE/FALSE to -1/0, then applying it again to negate the value, e.g., +1/0.

A single unary operator (-) coerces true/false values into -1/0. By using the double unary operaor, we coerce the values again to 1/0.