[Solved] Compare a single cell to a group of cells?

Discuss the spreadsheet application
Post Reply
Acidello
Posts: 13
Joined: Thu Nov 19, 2020 12:51 am

[Solved] Compare a single cell to a group of cells?

Post by Acidello »

Hi everyone! And thanks in advance for the help =)
I am struggling in a rather simple task, I am sure there is a formula for this but I can't find it. I am a very beginner user in Openoffice.

I need to compare the value of a single cell to each value of a range of cells, return "1" if I find a match, "0" if I don't (or if the source cell is empty).
I know a way in which I could do it, but the formula would get very large and it would also be time consuming, I am sure there is a more compact way.
I would usually do it like that:

value to compare: cell A1
range of cells: B1:Z1
formula: =IF(A1=0;0;IF(A1=B1;1;IF(A1=C1;1;IF(A1=D1;1;IF(A1=E1;1... ...IF(A1=Z1;1;0))))))))))))

I searched a lot on the forum, also on the Italian one (I am italian) and on google in general, but I found formulas like LOOKUP or MATCH which as far as I understand don't do exactly what I need (although perhaps with a complex setup I could use them as well).
Does anyone have a better solution to this? Thank you to anyone who reads this =)
Last edited by Acidello on Thu Nov 19, 2020 7:43 pm, edited 1 time in total.
Openoffice 4.1.13
Windows 10
User avatar
MrProgrammer
Moderator
Posts: 4908
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Compare a single cell to a group of cells?

Post by MrProgrammer »

Hi, and welcome to the forum.
Acidello wrote:I need to compare the value of a … cell to each value of a range …, return "1" if I find a match, "0" if I don't (or if the source cell is empty).
Value to compare: cell A1; Range of cells: B1:Z1
Formula: =IF(A1=0;0;IF(A1=B1;1;IF(A1=C1;1;IF(A1=D1;1;IF(A1=E1;1… …IF(A1=Z1;1;0))))…))))
=IF(ISBLANK(A1);0;SIGN(SUMPRODUCT(A1=B1:Z1)))
Based on your proposed formula, I will guess you want to return numeric values 0 and 1, not text values "0" and "1".

[Tutorial] The SUMPRODUCT function
Calc Functions listed by category
[Tutorial] Ten concepts that every Calc user should know

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Acidello
Posts: 13
Joined: Thu Nov 19, 2020 12:51 am

Re: Compare a single cell to a group of cells?

Post by Acidello »

Thank you so much!
This works, and exactly as I intended, and it is also compact!
Thank you, you saved my spreadsheet... =)
Openoffice 4.1.13
Windows 10
Post Reply