Google-sheets – How to check if value is in range of cells

google sheets

I want to check if the value of a cell exists in a range of cells. How can I do this?

Just like you would be able to do "if value in list_of_values" in Python for example.

Best Answer

You could use COUNTIF.

For example:

=COUNTIF(G:G,6) > 0  

if you want to find the number 6 in the range G:G, and/or

=COUNTIF(A1:B7,"d") > 0  

if you want to find d in the first seven rows of the first two columns.

COUNTIF will return the number of instances in its given range that are equal to its given value. It can also do a bit more complex conditioning (e.g all values higher than 6, or containing the letter A); see the docs for more info.