Question

I would like to set every negative value in a column of integers to 0. That is, set it to 0 IN THE SAME CELL. Of course, I could just use MAX(cell,0) if I wanted a new column.

I think Format Cells -> Format Code may do this, as it appears to support some kind of regex, but how do I replace any generic negative value with 0?

I don't know the syntax and can't find any documentation on it. This is a custom format I tried:

#,##0.00;"0.00"

The problem is, it just masks the negative values as "0.00". It doesn't replace the VALUE with 0. Calculations assume that cell still contains the negative value.

Was it helpful?

Solution 2

In OpenOffice / LibreOffice Calc, the following regex matches negative integer values:

^-[0-9]*

This allows you to simply replace every negative int value by any value in a single step. Don't forget to enable regex searching in the search options:

Search negative values using regex

OTHER TIPS

=if(A1-A2<0; 0; A1-A2)

If A1-A2 is less than 0, show 0, otherwise show A1-A2.

OR...

You can use conditional formatting!

Highlight the cells then, at the top, open Format > Conditional Formatting. Cell value is, less than, 0 Then hit New Style, name it Zero (or whatever), Open the Numbers tab. At the bottom where it says Format code, change whatever is in there to "0.00" (include the quotes). Hit OK. Make sure Cell Style is Zero. Hit OK. Done.

Hope that helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top