Counting Parentheses

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to identify certain cells by how many parentheses the cell contains. Some cells have one set ( ) and some cells have more than one set ( ) ( ). Is this possible?
Thanks.
 
=SUMPRODUCT(--ISNUMBER(FIND("(",A1:A4,FIND("(",A1:A4)+1)),--ISNUMBER(FIND(")
",A1:A4,FIND(")",A1:A4)+1)))




teddyb777 said:
I want to identify certain cells by how many parentheses the cell
contains. Some cells have one set ( ) and some cells have more than one set
( ) ( ). Is this possible?
 
=SUMPRODUCT(--ISNUMBER(FIND("(",A1:A4,FIND("(",A1:A4)+1)),--ISNUMBER(FIND(")
",A1:A4,FIND(")",A1:A4)+1)))
...

OP didn't mention the A1:A4 range, and it's highly questionable whether this
sort of thing should be done on multiple cell ranges without returning an array
with separate results for each cell.

Your formula returns the number of cells in which there are 2 or more left and
right parentheses rather than giving the number of paired parentheses in each
cell. If a categorization by number of parentheses is needed, then better to
operate on each cell separately. Crudely,

=MIN(LEN(A1)-LEN(SUBSTITUTE(A1,"(","")),LEN(A1)-LEN(SUBSTITUTE(A1,")","")))

and

=MAX(LEN(A1)-LEN(SUBSTITUTE(A1,"(","")),LEN(A1)-LEN(SUBSTITUTE(A1,")","")))

This is crude because it treats "))xy((", "(x)(y)", "((xy))" and all other
permutations the same. Given the OP's description, it's unclear to me whether
nested parentheses, "(())", would count the same as sequential pairs, "()()".
 
Back
Top