Format Function Different Formats for Different Numeric Values

Description

A user-defined format expression for numbers can have from one to four sections separated by semicolons. If the format argument contains one of the named numeric formats, only one section is allowed.

If you use

The result is

One section only

The format expression applies to all values.

Two sections

The first section applies to positive values and zeros, the second to negative values.

Three sections

The first section applies to positive values, the second to negative values, and the third to zeros.

Four sections

The first section applies to positive values, the second to negative values, the third to zeros, and the fourth to Null values.


The following example has two sections: the first defines the format for positive values and zeros; the second section defines the format for negative values.

"$#,##0;($#,##0)"
If you include semicolons with nothing between them, the missing section is printed using the format of the positive value. For example, the following format displays positive and negative values using the format in the first section and displays "Zero" if the value is zero.

"$#,##0;;\Z\e\r\o"
See Also

Format function, Format function — different formats for different string values.