Thread: parentheses
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default parentheses

"Brendy" wrote:
what a mean is when writing formulas that use different
functions and are nested, in what order should I use to put
these ( )[.] Eg =sum(a1:a4) I can understand but
sometimes when creating a formula 2 (( or 3((( are after
the first function in the formula. what I want to know is
there a simplier way of knowing if these double or treble
parentheses should be put at the start or end of the formula.
Hope I have explained myself a little better


I'm not sure. But with nested functions (and nested expressions),
the simple rule is: you balance parentheses as needed.

Consider an example of nested IF() functions in the false-part.

=IF(A10, ..., IF(B10, ..., IF(C10, ...) ) )

I have 3 parentheses at the end, not because of any arbitrary
rule about multiple parentheses, but because each IF() requires
a pair of parentheses as follows:

IF(A10, ..., ...)
IF(B10, ..., ...)
IF(C10, ..., ...)

It is merely "coincidence" that all 3 right parentheses -- one for
each IF() function -- occur next to each other. To make that
point clear, consider the case where those nested IF() functions
are in the true-part:

=IF(A10, IF(B10, IF(C10, ..., ...), ...), ...)

As for multiple parentheses at the start of a function, again it
is merely coincidence. Consider the following:

=IF(((A1+A2)/A3 + A4)*A5 0, ..., ...)

The 3 initial parentheses appear together, again not because
of any arbitrary rule about multiple parenthese, but simply
because of the need to groups subexpressions as follows:

IF(..., ..., ...)
(... + A4)*A5
(A1+A2)/A3

If I turn the conditional expression around, there would be
only one left parenthesis at the start of the IF() function, viz:

IF(0 < ((A1+A2)/A3 + A4)*A5, ..., ...)

The bottom line is: don't think of this as a rule for when
multiple parentheses are required; think only of balancing left
and right parentheses for each subexpression and function.

Does that help?