multiple conditionals in excel is there a better function to use - excel

I'm having a problem with my excel formula, the formula is supposed to basically be a bunch of if functions written out it looks like
If (h3< 1, H3+1),
If (h3>= 5 and H3<= 10, H3+2),
Else H3+3
I tried to put it into an excel formula based on what I saw online and some YouTube videos on if functions in excel but it's saying I added too many arguments. "Error: You've entered too many arguments for this function". Is there a better way to do this formula? Should I be using AND instead of multiple IF's? Does anyone have any advice or suggestions? Also any recommendations on how to improve with excel?
Here's my current formula:
'''
=IF(H3>10, H3+3,
IF(H3<=10, H3>=5, H3+2,
IF(H3<1, H3+1)))
'''
I expect for the formula to add either 1, 2, or 3 based on H3.

You have too many arguments in the second nested if statment
=IF(H3>10, H3+3,IF(H3<=10, H3>=5, H3+2, IF(H3<1, H3+1)))
If statements have 3 conditions
1) the logic statement
2) what to do if the logic statement is true
3) what to do if the logic statement is false
In your second in your second if statement you have 4 conditions - it looks like 2 logic statments H3<=10 AND H3>=5. If you want to use both of those logic statements, you will need to add in AND()
=IF(H3>10, H3+3,IF(and(H3<=10, H3>=5), H3+2, IF(H3<1, H3+1)))
Additionally, in this scenario, you only have 2 conditions for your final IF statement. You need to add in a final value for when all logic statements are false.
=IF(H3>10, H3+3,IF(and(H3<=10, H3>=5), H3+2, IF(H3<1, H3+1, "ADD VALUE FOR WHEN FALSE")))
Also be careful if you have blank cells, you might not get the answer you're looking for if H3 is ever blank.

Related

Excel percentage increase based on formula

I am trying to fill the sell price column in an Excel spreadsheet with the increased values in colors based on the round up columns value (1 to 50 green, 50 to 100 blue, 100 to 150 yellow, 150+ pink).
I've opted for the percentage table because some items can be sold for a lot more than what I have purchased them for, so that's just for my benefit. I am open to any other suggestions and I am new to this whole business thing.
I was using IF in my formula which would work great for using one percentage increase in the formula:
=IF($E27<50,ROUNDUP(I$27,-1))
If I try to enter a second argument like
=IF(OR($E28<50,ROUNDUP(I$28,-1)OR($E28>50,<100,ROUNDUP(J$28,-1))))
I will get an error.
I'm probably using the formulas wrong, I've tried "AND" and a couple other formulas, but I can't find anyone else trying to achieve the same or similar.
So something like this:
=IF($E28<50,ROUNDUP(I$28,-1),IF($E28>50,ROUNDUP(J$28,-1),"Error"))
But not sure what the <100 was for.
Although the problem is not completely clear, I understand that you want to add a formula with nested if statements.
I will recommend you to try nested ifs in parts.
=IF($E27<50,ROUNDUP(I$27,-1),"First if condition is false")
If everything is working as per the requirement then edit that text in the formula to add another if statement.
=IF($E27<50,ROUNDUP(I$27,-1),IF(OR(condition 1, condition 2,more conditions),"value if true","value if false"))
In the second argument provided by you, the arguments of the OR function has not been properly provided. Ensure that all the arguments of an OR function are conditions separated by a comma.
$E28<50 This is a condition so it's ok.
But other arguments are not making sense.
Also, using OR multiple times inside the first OR arguments is not clear.
It would be beneficial if you could provide the basic table and mention the requirement clearly.

Multiple IF statements in Excel not working

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.
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
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.

Combining multiple IF-statements into one formula

I am constructing a formula to act as an extra 'control cell' for my excel worksheet.
The if statements in text with the expected result:
If D2=0 and E2=0 and F2=0 =>""
If D2=0 and E2>0 and F2=0 =>"m of m2"
If D2>0 and E2>0 and F2=0 =>"m2 of m3"
If D2>0 and E2>0 and F2>0 =>"m3"
If D2>0 and E2=0 and F2>0 =>"m2"
If D2=0 and E2>0 and F2>0 =>"m2 of m3"
If D2=0 and E2=0 and F2>0 =>"m"
If D2>0 and E2=0 and F2=0 =>"m"
I'll converting this formula to vba afterwards, but my knowledge of vba is pretty limited so I like to start with just the excel formula.
Thanks in advance.
*edit: so far the formula always returns "m3" so it acts like all the cells are >0 even if they are empty/have a 0 value.
Formula so far (it's in dutch so als=if)
=ALS(D3=0&E3=0&F3=0;"";ALS(D3=0&E3>0&F3=0;"m of m2";ALS(D3>0&E3>0&F3=0;"m2 of m3";ALS(D3>0&E3>0&F3>0;"m3";ALS(D3>0&E3=0&F3>0;"m2";ALS(D3=0&E3>0&F3>0;"m2 of m3";ALS(D3=0&E3=0&F3>0;"m";ALS(D3>0&E3=0&F3=0;"m";""))))))))```
One way to interpret your table of results is that the value is equal to 0 or its not. your table does not cover the possibility of of values being less than 0. With this understanding one possible NESTED IF function would be:
=IF(D2=0,IF(E2=0,IF(F2=0,"","m"),IF(F2=0,"m of m2","m2 of m3")),IF(E2=0,IF(F2=0,"m","m2"),IF(F2=0,"m2 of m3","m3")))
Alternatively in excel you could use the CHOOSE function. Since each result is unique and its based based on binary results you could use the following formula to generate an index number from 1 to 8:
1+(F2>0)+(E2>0)*2+(D2>0)*4
Drop that in a CHOOSE function and its much more shorter manageable then nested IF. It could look as follows:
=CHOOSE(1+(F2>0)+(E2>0)*2+(D2>0)*4,"","m","m of m2","m2 of m3","m","m2","m2 of m3","m3")
now not being a VBA guru either, I am not sure how CHOOSE would translate over to VBA. But that would be another question!
UPDATE: ALTERNATE IF function
=IF(AND(D2=0,E2=0,F2=0),"",IF(AND(E2=0,D2<>F2),"m",IF(AND(D2=0,E2>0,F2=0),"m of m2",IF(AND(E2>0,D2<>F2),"m2 of m3",IF(AND(D2>0,E2=0,F2>0),"m2","m3")))))
There are many ways to go through the logic. In this case I was able to group the IF functions by results.

Excel IF Statement - Multiple conditions in columns

Excel screenshot
I want to run a logical test that will execute either of two pieces of code based on a boolean outcome in MS Excel.
I have attached a sample of data. I want to run a logical IF test that executes either of two other functions based on TRUE or FALSE if column A contains "February" and column B contains the word "Breakfast" - but both conditions have to be in the same row, and can appear more than once (just has to be greater than zero). This is the code I came up with:
=IF(AND(COUNTIF(A:A,"February")>0,(COUNTIF(B:B,"*Breakfast*")>0)),"Run this code","Runthatcode")
I'm currently learning programming and Excel so my knowledge is pretty limited right now.
Many thanks.
Fraser
Try using the COUNTIFS function to accomplish this.
=IF(COUNTIFS(B:B, "ValueA", C:C, "ValueB") > 0, Function1, Function2)

How to use multiple separate formulas in a single "IF" in Excel?

I have a basic understanding of excel formulas work and have used this site many times to broaden my knowledge, however, I'm stuck on the below and I'm hoping someone can assist me.
I'm trying to create a formula to work out if a KPI has been met. I have 3 separate formulas that I need to combine into one.
=IF(AND(E2="1",S2>0.041667),"YES","NO")
=IF(AND(E2="2",S2>0.125),"YES","NO")
=IF(AND(E2="3",S2>0.25),"YES","NO")
How do I do this?
I think you just need to use an OR to combine them. See below:
=IF(OR(AND(E2="1",S2>0.041667), AND(E2="2",S2>0.125), AND(E2="3",S2>0.25)) ,"YES","NO")
The OR requires at least one argument to be true, so the statement will evaluate to TRUE if at least one of the the AND statements returns true.
A bit simplified with the CHOOSE function (results in #VALUE! error if E2 is not 1, 2, or 3) :
=IF(S2 > CHOOSE(E2, 0.041667, 0.125, 0.25), "YES", "NO")

Resources