2

I would like to set a multiple IF statement for my formula. The reason behind it is, that I need to switch off the values (mark them as N/A and NA) which are equal to the other certain values as follows:

LP372/24/60+1=($NO372-720)/24/60+1 => mark them as N/A - the values, which don't happen during the midnight

and

LP372/24/60+1=$NO372/24/60+1 => mark them as NA - the values, that don't happen during the midday

The problem is, that I can't keep them under one IF statement, because I need the division.

So far I used only one IF statement (the nested one), which looks as follows:

=IF(OR((LP372/24/60+1)=(($NO372-720)/24/60+1), OR((LP372/24/60+1)=($NO372/24/60+1))),"N/A",LP372/24/60+1).

The value of NO372 corresponds to the rough time of the local midday. Substracting the 720 we are getting the rough midday for this location, knowing that the single day counts 24 hours x 60mins = 1440mins.

The formula above gives a nice result, but without the division between midday and midnight, which I am talking about.

enter image description here

Following my older query about the similar issue:

Double nested IF statement formula in Excel

I tried to solve it like this:

=IF(COUNTA(E1116:E1481),IF(OR((LP372/24/60+1)=(($NO372-720)/24/60+1),OR((LP372/24/60+1)=($NO372/24/60+1))),"N/A",LP372/24/60+1),"NA")

where the range E1116:E1481 corresponds to the whole year period (1.01 - 31.12). Unfortunately I got nothing, similarity to this formula:

=IF(COUNTA(E1116:BC1116),IF(OR((LP372/24/60+1)=(($NO372-720)/24/60+1),OR((LP372/24/60+1)=($NO372/24/60+1))),"N/A",LQ510/24/60+1),"NA"),

where the E:1116:BC1116 range correspond to the all columns - circumstances as occur on January 1. This formula was still not correct.

I found something on the web about the multiple IF statements:

which led me to the following formula

=IF((LP372/24/60+1)=(($NO372-720)/24/60+1);"N/A";IF((LP372/24/60+1)=($NO372/24/60+1);"NA")LP372/24/60+1)

Unfortunately again not correct.

The last attempt was an answer provided here:

Multiple IF statements in Excel

on which basis I built up another formula

=IF((LP372/24/60+1)=(($NO372-720)/24/60+1),"N/A",LP372/24/60+1,IF((LP372/24/60+1)=($NO372/24/60+1),"NA"))

this time Excel said, that I've entered too many arguments.

Is there a way to set up multiple IF statements? I need to:

  • make the values equal to midnight as N/A,
  • make the values equal to midday as NA
  • keep the other values as they stand
7
  • I'm not sure I fully understand what you are wanting to do, but if all you want to do is check a time value in a cell and mark a different cell as either "N/A" or the other value based off of if the time is midnight or noon, why can't you just do something like this: =IF(OR(HOUR(B19)=12,HOUR(B19)=0),"N/A",B19) ? this checks the hour of the cell (in this case B19) and if the hour is 0 or 12 (midnight or noon) you get N/A, else you get the value of the cell. Commented Jul 21, 2020 at 15:01
  • I don't see how it's possible that you are getting FALSE if you are copying and pasting my formula exactly into your sheet. If you are trying to use my formula as part of another formula that could result in you getting FALSE. How are you trying to implement my formula? can you post the exact final version of the formula you are using as well as the value in the cell you are examining? Commented Jul 21, 2020 at 15:21
  • =IF((LP372/24/60+1)=(($NO372-720)/24/60+1),"N/A",IF((LP372/24/60+1)=($NO372/24/60+1),"NO")) Thhis is exactly what I am writing. Instead of timevalues I am getting FALSE. Maybe shall I do sth like this: =IF((LP372/24/60+1)=(($NO372-720)/24/60+1),"N/A",IF((LP372/24/60+1)=($NO372/24/60+1),"NO"),LP372/24/60+1) ? Commented Jul 21, 2020 at 15:23
  • 1
    the reason you are getting false is because the last IF statement in the formula in the last comment does not have the final value in it. if the formula works other than just that here is the version that points out where to put the reference to your cell you want the timestamp from: =IF((LP372/24/60+1)=(($NO372-720)/24/60+1),"N/A",IF((LP372/24/60+1)=($NO372/24/60+1),"NO","your timevalue cell reference goes here")) Commented Jul 21, 2020 at 15:34
  • 1
    yes. it's really easy to get lost when nesting IF statements, what I do when doing something like that is when adding a new IF statement, I type the structure out first like this: IF( , , ) because each IF statement has 3 parts inside the parens: first is the condition you are checking against, second is what you want if that condition is true, third is what you want if the condition is not true. the reason you were getting FALSE is because you were leaving out the third part in the IF statement. so, because you didn't give that final value, it just displayed FALSE Commented Jul 21, 2020 at 18:35

1 Answer 1

1

This question was answered in the comments, but I thought I would add an answer with an example of how to nest IF statements for anyone that found this question because they are having issues with nesting IF statements.

When you add an IF statement to a formula in excel, you have to keep in mind that IF statements have 3 parts separated with commas:

  • The first value is the condition you are going to check
  • The second value is the value you want returned if that condition is true
  • The third value is the value you want returned if that condition is false

So here's an example that illustrates that:

=IF(condition to check, value if condition is true, value if condition is false)

Here is an example IF statement:

=IF(A1="Hello","World","something else")

If you are getting FALSE returned then your IF statement probably looks like this:

=IF(A1="Hello","World")

Notice that there are only 2 values inside this IF statement: the condition you are checking (A1="Hello") and what you want displayed if that is true ("World"). FALSE would be displayed if the value in A1 is something other than Hello because you haven't included the third value in the IF that defines what you want displayed if A1 is not Hello (this value is listed as something else in the example above)

It's best to try and avoid nesting IF statements if you can because they can be hard to keep track of. I would suggest using AND() or OR() instead if you can. They are very similar to each other, you list multiple conditions within the parens separated by commas that you will be checking against, and both evaluate to either True or False. The only difference is that for AND() every condition within the parens needs to be true for it to evaluate to True where OR() only one of the conditions listed in the parens needs to be true for it to return True.

So, for example, if you wanted to display World if A1 is Hello or Hi and you were to use nested IF statements it would look like this:

=IF(A1="Hello","World",IF(A1="Hi","World","something else"))

which in my opinion is really ugly. however, if you used OR() instead of nesting IF statements it would look like this:

=IF(OR(A1="Hello",A1="Hi"),"World","something else")

AND() works the same way, but instead of just needing one condition within the parens to be true to return True as OR() does, with AND() all conditions inside of the AND() need to be true to display your value instead of just one. here's an example AND():

=IF(AND(A1="Hello",B1=""),"World","something else")

in this case "World" would be displayed only if A1 is Hello AND B1 is empty

for both AND() and OR() you can have more than just 2 values inside if you need to check for more than 2 conditions, you just need to separate them each with commas, like this:

AND(condition1, condition2, condition3, ....)

OR(condition1, condition2, condition3, .....)

but, if you have to use nested IF statements, the easiest way I've found is to type IF( , , ) first thing to make sure you are allowing for all 3 values that need to be inside of the IF and you have the right amount of values inside the IF. If you are getting the message You've entered too many arguments for this function it is because you have entered more than 3 values inside your IF, like this:

=IF(A1="Hello","World","something else","this value is causing the issue")

so, to properly nest an IF in your formula, type IF( , , ) first off where you want the IF statement to be in your formula and then just fill in the blanks, then you avoid entering too few values which results in FALSE being displayed if your condition is not true or You've entered too many arguments for this function because you entered more than 3 values in your IF

Hope this helps to understand IF statements and how to nest them properly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.