Google Sheets – Value in Cell Different from Text

google sheets

Within one cell, I would like the value of the cell to be treated differently from the text inside that cell. For example, I would like the cell to display "$148 (123 euros)", but the value to be treated as 148 when I am summing that cell and another.

Best Answer

Given your example — "$148 (123 euros)" — you won't simply be able to refer to the cell when trying to do math with it.

Let's say that your above string is in A2 and you want to divide the USD amount by 2 in cell B2. In cell B2, you'd use something like this:

=REGEXEXTRACT(A2,"\d+")/2

The REGEXEXTRACT will extract the first group of digits it finds, on which math can now operate.

Keep in mind that if you only want to extract the number without any further math, you'll need to wrap the REGEXEXTRACT in VALUE:

=VALUE(REGEXEXTRACT(A2,"\d+"))

This is because REGEXEXTRACT extracts strings. When you apply further math operations, Sheets automatically knows you want to treat the extracted portion as a number. But if no math is applied, the extraction remains a string. So VALUE converts it to a number. In lieu of this, you could also just apply the math of *1:

=REGEXEXTRACT(A2,"\d+")*1