Pergunta

I have an excel spreadsheet with three columns (C, D, E): R, G, B.

Each column will have a value in it ranging from 0 to 255. Each set of three values (each row) represents a colour. A shade of grey is identified by all three columns (for a given row) having the same value. There are 554 rows (not that this makes a difference to the solution).

Without adding extra columns, is there a way to use countif() to count the shades of grey in the range (C:E).

I have already tried a number of variations (based on solutions to different problems here on SE) - none of which work:

=COUNTIF(C:E,AND(C:C=D:D,D:D=E:E))

=COUNTIF(C:E,AND(OFFSET(C:E,0,0,1,1)=OFFSET(C:E,0,1,1,1),OFFSET(C:E,0,0,1,1)=OFFSET(C:E,0,2,1,1)))

=COUNTIF(C:E,AND(INDEX(C:C,ROW())=INDEX(D:D,ROW()),INDEX(D:D,ROW())=INDEX(E:E,ROW())))

I believe there has to be a solution - I just haven't stumbled on it yet. Any ideas would be appreciated. If countif() is the wrong function to use, then I am obviously open to alternative suggestions.

Foi útil?

Solução

Well, you can use SUMPRODUCT:

=SUMPRODUCT((C2:C555=D2:D555)*(C2:C555=E2:E555))

C2:C555=D2:D555 checks whether each cell in C2:C555 is equal to the corresponding cell in D2:D555 and returns an array of TRUE and/or FALSE.

C2:C555=E2:E555 does the same thing, but with columns C and E.

Multiplication of TRUE and FALSE values give an array (another array) of 1s and 0s where only TRUE*TRUE gives 1.

SUMPRODUCT then sums each of the individual 1s and 0s. You can use SUM instead, but it would require array formula entry (i.e. Press Ctrl+Shift+Enter for it to work properly).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top