Forum Discussion

jamessavery1996's avatar
jamessavery1996
Copper Contributor
May 07, 2021
Solved

Running an 'if' function if other criteria is met...

Hello Excellers!

 

If have the following formula in my spreadsheet:

 

 =if(if(D5="", "", if(mod(D5-$C5,1)*24<4, 5, 0))=0, "", if(D5="", "", if(mod(D5-$C5,1)*24<4, 5, 0))

 

However, I'd like this to run/only apply if other cells contain specific values. For example, if this formula is in P5, I'd like to to only run/apply if B5 contains the letter 'C' OR the letter 'D'. If it contains 'A', 'B', 'E', 'A_S' or 'A_R', it needs to not run/stay blank.

 

Anyone can help me? @excel

  • SergeiBaklan's avatar
    SergeiBaklan
    May 07, 2021

    jamessavery1996 

    Perhaps something like this

    =IF( NOT(OR(B5="C",B5="D")),
      IF(D5="",
        "",
        IF(
            IF(MOD(D5-$C5,1)*24<4,5, 0)=0,
            "",
            IF(D5="",
              "",
              IF(MOD(D5-$C5,1)*24<4, 5, 0)
            )
        )
      ),
    "")

10 Replies

  • Twifoo's avatar
    Twifoo
    Silver Contributor

    jamessavery1996 

    Perhaps, this formula in P5 fulfills your requirements: 

    =IF(SUM(COUNTIF(B5,{"*c*","*d*"})),
    IF(D5="","",
    IF(MOD(D5-C5,1)*24<4,5,0)),
    "")
    • jamessavery1996's avatar
      jamessavery1996
      Copper Contributor
      It won't. There's another formula in 'B' that ensures they contain one of the following: A, B, C, D, E, A_R, A_S. So I need the above formula to only run/apply if the relevant 'B' contains either letter C or D.
      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        jamessavery1996 

        Perhaps something like this

        =IF( NOT(OR(B5="C",B5="D")),
          IF(D5="",
            "",
            IF(
                IF(MOD(D5-$C5,1)*24<4,5, 0)=0,
                "",
                IF(D5="",
                  "",
                  IF(MOD(D5-$C5,1)*24<4, 5, 0)
                )
            )
          ),
        "")

Resources