Identify cell containing given text in LibreOffice Calc

libreoffice-calcsearch

Is there a function in LO Calc that will find a cell with the given text?

The search and find functions appear to give a location within a string. That is, if I search for the text "a" within two cells, one of which contains "xxxa" and the other contains "bbb", the answer will be 4.

This is not what I need. I need to find which cell has the text in question.

Best Answer

Just use the MATCH() function. Since it supports regular expressions, you can use MATCH() to search for partial strings.

Here's an example:

enter image description here

The lookup array is A1:A4, the search criterion is .*a.* (this is a regular expression, for syntax see link above). The result of the formula =MATCH(".*a.*";A1:A4;0) is 2, since the second cell in the lookup array is the first cell that matches the search pattern.

EDIT:

Regarding the regular expression: here's a list of regular expression characters. The expression .*a.* consists of:

  • the literal a, matching a single a character;
  • the dot ., matching any character;
  • the asterisk *, a quantifier, meaning "zero or more", regarding the preceding character.

So, the regex pattern matches every cell content containing an a, preceded and followed by any number of other characters. To get acquainted with regular expressions, check the RegExr or the online regex tester.

Related Question