Home » excel » excel – How to recycle long formula within the same if statement

# excel – How to recycle long formula within the same if statement

Questions:

I have an `if` statement that looks like this:

``````=If(LONG 1000-CHARACTERS FORMULA > 0, LONG 1000-CHARACTERS FORMULA, "null")
``````

In English, the cell will return the 1000-character formula output if that 1000-character formula is greater than 0.

The problem is copying and pasting the long 1000-characters formula.

A simple work around would be storing that 1000-character formula in a hidden cell (i.e., B2), then writing this:

``````=If(B2 > 0, B2, "null)
``````

But, I don’t want to use the above method because I have many cells with different long formulas.

Instead, is there a way to recycle the 1000-characters formula within the `If` statement? A possible outcome might look like:

``````=If(LONG 1000-CHARACTERS FORMULA > 0, xyz, "null")
``````

You need a function which has an inverse and is only valid for positive numbers. A good candidate is

``````y=1/sqrt(x)
``````

or

``````y=x^0.5
``````

whose inverse is

``````x=y^-2
``````

So the formula becomes

``````Iferror(((long_formula^-.5)^-2,"null")
``````

However from the comments linking back to the previous question it seems that the result (of countifs) can’t be a negative number so you could simplify it down to 1/(1/long_formula) as in @Gary’s Student’s (now deleted) answer.

Edit

I had forgotten that there is another way of doing this – using the Text function to format the number differently if it is negative or zero:

``````=TEXT(long_formula,"general;\n\u\l\l;\n\u\l\l")
``````

The result is a string, so would need to be converted to a number if (say) you wanted to compare it with another number.