IF statement returning false with no data - excel

I am working on an elongated IF statement that produces different outputs depending on the start of a part number e.g. 3XXXXXXX = Software, 4XXXXXXX = Hardware.
The problem I am having is that the formula outputs FALSE when a part number is yet to be given to the row.
=IF(B2>0,IF(LEFT(D2,1)="1","Assembly",IF(LEFT(D2,1)="2","Sub-Assembly",IF(LEFT(D2,1)="3","Software",IF(LEFT(D2,1)="4","Hardware",IF(LEFT(D2,1)="5","Chemical",IF(LEFT(D2,1)="6","Spare",IF(LEFT(D2,1)="7","Spare",IF(LEFT(D2,1)="8","Document",IF(LEFT(D2,1)="9","Misc",""))))))))))
Please let me know if you can spot where I am going wrong!

You have at least two other options, both of them providing you better maintainable code.
If you use Excel 2016 or higher, there is the SWITCH function. Your formula will then look much more readable:
=IF(B2>0,SWITCH(LEFT(D2,1),"1","Assembly","2","Sub-Assembly","3","Software","4","Hardware","5","Chemical","6","Spare","7","Spare","8","Document","9","Misc",""))
Even in earlier Excel versions, you may use a lookup table, which provides you much higher versatility. Create a table of your categories, you may place them in a separate sheet Categories:
Use VLOOKUP function together with IFERROR to provide the default value when not found:
=IFERROR(VLOOKUP(LEFT(D2,1),Categories!$A$1:$B$9,2,FALSE),"")

You're not putting any value for the first big condition (if B2 is not > 0)
Try this instead:
=IF(B2>0,IF(LEFT(D2,1)="1","Assembly",IF(LEFT(D2,1)="2","Sub-Assembly",IF(LEFT(D2,1)="3","Software",IF(LEFT(D2,1)="4","Hardware",IF(LEFT(D2,1)="5","Chemical",IF(LEFT(D2,1)="6","Spare",IF(LEFT(D2,1)="7","Spare",IF(LEFT(D2,1)="8","Document",IF(LEFT(D2,1)="9","Misc",""))))))))),"")

You can simplify your formula like this:
=IF(B2<=0,"",CHOOSE(LEFT(D2,1),"Assembly","Sub-Assembly","Software","Hardware",
"Chemical","Spare","Spare","Document","Misc"))

Related

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 Not returning the appropriate Value

I'm trying to grade students by giving them A or B depending on their score. If someone is having absent instead of a score, I return a value of the cell.
However, it does not return the value of the cell. The reference records are in a separate sheet called raw. I think it may be because I'm trying to return a string data.
I am using Excel 2007. Here's the formula:
=IF(raw!E6>=75,"AA",IF(raw!E6>=70,"AB",IF(raw!E6>=60,"B",IF(raw!E6>=50,"C",IF(raw!E6>=40,"D",IF(raw!E6<40,"RT",raw!E6))))))
Don't use Nested IFs if you can avoid it. Instead, use a banded VLOOKUP: it's many times more efficient, and a heck of a lot simpler to troubleshoot. Something like this:
=IF(ISNUMBER([#Score]),VLOOKUP([#Score],Table1,2,TRUE),"Absent")
Notes:
The above uses Tables and the associated Table Notation. I always use
Tables when I can, because they reduce spreadsheet administration and
the Structured Table References have intrinsic meaning.
The VLOOKUP must have TRUE as the forth argument, and the lookup
table must be sorted in ascending order.
The lowest score must be zero, so that anything below 40 gets a "Retake" grade.
Depending on whether or not the students' scores are in whole percentage figures (i.e. 75, 63, etc), you could use the INT-function to force interpretation of the input field as an integer (not that it always round down a score, which I suppose seem to be ok with the nested if-structure you're using here. Your function would then be:
=IF(INT(raw!E6>=75),"AA",IF(INT(raw!E6)>=70,"AB",IF(INT(raw!E6)>=60,"B",IF(INT(raw!E6)>=50,"C",IF(INT(raw!E6)>=40,"D",IF(INT(raw!E6)<40,"RT",raw!E6))))))
you just need to change you last IF condition (raw!E6<40,"RT) because excel will give RT to all the score which is below 40 so add a and condition like if raw!E6>0 , this should resolve your work
if(and(raw!E6<40mraw!E6>0),"RT,raw!E6)
Hope this helps

MS Excel IF statement confusion

I'm trying to make a spreadsheet for some calendars that I'm selling. I have a pricing scheme which depends on how many calendars a customer buys. I want to be able to keep track of sales, but I don't want to have to input the price per unit for each sale. I set up an IF statement that seems to work except for the last variable. Here's a screenshot:
As you can see, it works all the way to the last one. After the number reaches 11, the price per unit should drop to 6, but it doesn't! I know it must be a simple fix, but I don't know much about IF statement, so I'm stuck. Please help!
If you set up your price table similar to my set-up below, you can use a VLOOKUP formula to make it more flexible.
The formula in H10 is:
=VLOOKUP(G10,$B$1:$C$5,2,TRUE)
Enter and drag down.
The benefit of this approach is that you can change the lower bound count on the left and you'll get an adjustment without having to update the formula. Try changing the 2 in Count to 3 and you'll see the adjustments right away.
An added benefit is you can add some more values to the table for further pricing brackets.
If you must use an IF statement, try:
=IF(G10=1,9,IF(G10<=5,8,IF(AND(G10>5, G10<11),7,IF(G10>=11,6,IF(G10="","")))))
The problem with yours is it will never read the if(G10>=11 part because it has already evaluated if(G10>5
If it should have no output when G10 is blank, use the following variant:
=IF(ISBLANK(G10),"",IF(G10=1,9,IF(G10<=5,8,IF(AND(G10>5, G10<11),7,IF(G10>=11,6,IF(G10="",""))))))
I agree with #Nanashi that putting the price thresholds in a separate table and using vlookup is a better solution. That would make it possible to change the price points without having to edit multiple formulae.
But to just get your formula working, try this: =if(g10="","",if(g10=1,9,if(g1<=6,8,if(g10<=10,7,6))))
Notice that:
You don't need (and probably don't want) quotes around your numeric
values
The order of tests is important. In your original, the test for g10>=11 is never reached because it is in the else part of the g10>5 function.
A properly constructed table of quantities and pricing coupled with a VLOOKUP formula would be the best way to go and eases future pricing changes. But for the sake of diversity, your straightforward pricing structure could also be handled by the following:
=(6+(G10<11)+(G10<6)+(G10<2))*(G10>0)
In the formula, "G10>5" should be "G10<=10". Otherwise, when it gets to 11, it still meets the G10>5 criteria.

Speed up Excel formulas

Is there anyway to rewrite this formula to speed up Excel processing?
My spreadsheet has become terribly slow!
=SUMPRODUCT((Sheet1!J:J=Sheet2!A2)*(Sheet1!G:G="Windows XP")*(Sheet1!B:B="Desktop")*(Sheet1!M:M<>"Refresh >=Q2 2014")*(Sheet1!M:M<>"Release 2013")*(Sheet1!M:M<>"Release 2014")*(Sheet1!M:M<>"N/A NVM")*(Sheet1!M:M="No")*(Sheet1!M:M="N/A"))
As written your formula will always return zero because the last two conditions are mutually exclusive - did you mean those last two to be <> rather than = (or did you refer to the wrong columns)?
In any case I can see from the use of whole columns that you must be using Excel 2007 or later (your current formula would give an error otherwise) in which case COUNTIFS will be much faster, i.e. assuming the last two conditions should be adjusted as I suggested try this version:
=COUNTIFS(Sheet1!J:J,Sheet2!A2,Sheet1!G:G,"Windows XP",Sheet1!B:B,"Desktop",Sheet1!M:M,"<>Refresh >=Q2 2014",Sheet1!M:M,"<>Release 2013",Sheet1!M:M,"<>Release 2014",Sheet1!M:M,"<>N/A NVM",Sheet1!M:M,"<>No",Sheet1!M:M,"<>N/A")
If you do need to use SUMPRODUCT then restrict the ranges rather than using whole columns
I don't think that there is really a chance to speed up Excel Formula. But you could save your File in binary code (.xlsb). Losing some compatibility but improving performance.
You also could stop auto (re-)calculations of ther Formula, then you have to manualy refresh. This will let you edit the file much smoother.

Excel Serial If statements

I'm new to Excel, and I'm struggling with a formula. Essentially, what I'm looking for is to filter a cell through a set of procedures using a formula (this part isn't strict).
For example
Let's say I have a cell, A1. I'm trying to perform different calculations on this based on whether it is between a certain range of values. The problem is, it can be within several ranges.
Pseudo-Code representation
If(A1 > 187.5) {
// Run some code here.
}
If(A1 > 150) {
// Run some code here.
}
NOTE : The above example is only to illustrate the logic of sequential if statements.
Note that I Do not want a nested If statement. I'm just trying to run the same value through various checks. How do I do this in an Excel formula?
The best I can come up with is something like the following.
=(A1>187.5)*<some expression>+(A1>150)*<some expression>+....
The result of this will be some single value. (The straightforward way to get multiple values is to have the individual terms in separate cell.
If you want the result to reflect one among several mutually exclusive outcomes, then you would want to go with:
=(A1>187.5)*<some expression>+(A1>150)*(A1<=187.5)*...etc.
There are many ways to achieve this. One way is to use nested conditions like this:
=IF(Something, do something, IF(something else, do something, do something))
This is good if you want to condensate the formula a bit but arguably leads to more cluttered formulas. According to the FAST-Standard organization, those cases of nested conditions should be replaced by the use of flags. The most simple case would be, for example, where you would be looking for a rebate percentage according to a sales amount. In multiple cells you would have IF conditions evaluating to true only if the value matches that specific range. Then, your formula can be as simple as a SUMPRODUCT of your flags with your rebates percentages.
This is one example, but it can be applied to other cases very well too.
if there is a relationship between the numbers your checking for its very likely you can use
=CHOOSE(FLOOR(A1/160,1)+1,"<160",">160")
Which would put your 150 in the first and leave your 185 in the second

Resources