Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return if all Excel column values don't agree

I have the following data in an Excel Spreadsheet:

    A  B  C
 1  b  b  b

I would like to put a formula in the column after the data which compares each (text) value in the row, and returns TRUE if they're all the same ie A=B=C. I would like it to return FALSE if one or more of the values don't agree. ie

    A  B  C  D
 1  b  b  b  TRUE
 2  b  e  b  FALSE
 3  e  b  b  FALSE

I'm aware of logical functions like AND, hence could construct something like

AND(A1=B1,A1=C1.. etc), however, this soon gets unwieldy as soon as the number of columns increases.

Restructuring the data isn't do-able.

Does anyone know an OOTB / VB solution?

like image 804
trickwallett Avatar asked Jan 21 '23 07:01

trickwallett


1 Answers

If the countif finds the same number as the count then they are all the same.

=IF(COUNTIF(A1:C1,A1)=COUNTA(A1:C1),"true","false")

Hope this is what you are looking for, you just need to extend the ranges for however many columns you want to test.

Update

As pointed out in the comment this fails to return the right result if the dataset has blank cells.

This will return false even if there is a blank cell in the range:

=IF(AND(COUNTIF(A1:C1;A1)=COUNTA(A1:C1);COUNTBLANK(A1:C1)=0);"true";"false")
like image 69
Alan Whitelaw Avatar answered Jan 29 '23 10:01

Alan Whitelaw