Counting Parentheses

T

teddyb777

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.
 
D

Dave R.

=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?
 
H

Harlan Grove

=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, "()()".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top