How do I avoid repeating long formulas in Excel when working with comparisons?

前端 未结 3 1025
鱼传尺愫
鱼传尺愫 2020-12-17 06:42

I know that something like the following

=IF(ISERROR(LONG_FORMULA), 0, LONG_FORMULA)

can be replaced with

=IFERROR(LONG_FOR         


        
相关标签:
3条回答
  • 2020-12-17 07:12

    If you're comparing against a threshold amount, I would consider checking out ExcelJet's recent blog post about Replacing Ugly IFs with MAX() or MIN().

    Also, the MAX() and MIN() functions are much more intuitive than using lessor known functions like EXP() and LN().

    0 讨论(0)
  • 2020-12-17 07:13

    I was able to come up with the following:

    =IFERROR(EXP(LN(REALLY_LONG_FORMULA – threshold)) + threshold, 0)
    

    It works by utilizing the fact that the log of a negative number produces an error and that EXP and LN are inverses of each other.

    The biggest benefit of this is that it avoids accidentally introducing errors into your spreadsheet when you change something in one copy of REALLY_LONG_FORMULA without remembering to apply the same change to the other copy of REALLY_LONG_FORMULA in your IF statement.

    Greater than comparisons as in

    =IF(REALLY_LONG_FORMULA>=threshold,0,REALLY_LONG_FORMULA)
    

    can be replaced with

    =IFERROR(threshold-EXP(LN(threshold-REALLY_LONG_FORMULA)),0)
    

    Example below (provided by @Jeeped):

    For strict inequality comparisons use SQRT(_)^2 as pointed out by @Tom Sharpe.

    0 讨论(0)
  • 2020-12-17 07:27

    Comparing Ln Exp with SQRT ^2:-

    because SQRT(0) gives 0 but ln(0) gives #NUM!

    So you can choose which one to use depending whether you want the equality or not.

    These also work for negative numbers - in theory.

    0 讨论(0)
提交回复
热议问题