I need to select cels starts with this format (patern) "???. * Nr.?? CO*", and i write formula:
=IF(COUNTIF(A2;"<>???. * Nr.?? CO*");"NO";"OK")
In this selection i want to filter only cells starts wit "Pro.", "Ext." and "Fun.", and i write second formula:
=IF(SUM(COUNTIF(A2;{"Pro. *";"Ext. *";"Fun. *"}))=0;"NO";"OK")
Then i combine this both formulas in one single good formula:
=IF(OR(COUNTIF(A2;"<>???. * Nr.?? CO*");SUM(COUNTIF(A2;{"Pro. *";"Ext. *";"Fun. *"}))=0;);"NO";"OK")
And its working very well, but...
How is possible to combine both formulas without OR function? or
Exist some alternatives for this result?
Not entirely clear to me, but did you mean:
=IF(SUM(COUNTIF(A2,{"Pro","Ext","Fun"}&". * Nr.?? CO*")),"OK","NO")
I wrote a formula which exceeds 8192 characters and I really need to reach the result of the formula. Actually it is repetetive calculation for different conditions. I'm sure when you see the formula you will get the idea. But there is short explanation below:
There are 10 different sources and regarding choosen source formula should work.
Regarding choosen currency I need to get result of related calculation.
Right now it is 10.290 chars.
Since this is my first question and I'm kinda new on Excel any help would be appreciated.
*Expected result need to be shown on "unit price" column and different for each item.
=IFERROR(IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="TL";IF(core!$H29="TL";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="USD";core!$I29*core!$N$2+core!$I29*core!$N$2*core!$F29+core!$I29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3+core!$I29*core!$N$3*core!$F29+core!$I29*core!$N$3*core!$g29;"")));
IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$I29/core!$N$2+core!$I29/core!$N$2*core!$F29+core!$I29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3/core!$N$2+core!$I29*core!$N$3/core!$N$2*core!$F29+core!$I29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";(core!$I29/core!$N$3+core!$I29/core!$N$3*core!$F29+core!$I29/core!$N$3*core!$g29);IF(core!$H29="USD";(core!$I29*core!$N$2/core!$N$3+core!$I29*core!$N$2/core!$N$3*core!$F29+core!$I29*core!$N$2/core!$N$3*core!$g29);IF(core!$H29="EURO";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;""))))))))))));
IF(core!$D$11=2;IF($F15>0;IF(core!$D$7="TL";IF(core!$H29="TL";core!$K29+core!$K29*core!$F29+core!$K29*core!$g29;IF(core!$H29="USD";core!$K29*core!$N$2+core!$K29*core!$N$2*core!$F29+core!$K29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$K29*core!$N$3+core!$K29*core!$N$3*core!$F29+core!$K29*core!$N$3*core!$g29;"")));
IF(core!$D$11=2;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$K29/core!$N$2+core!$K29/core!$N$2*core!$F29+core!$K29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$K29+core!$K29*core!$F29+core!$K29*core!$g29;IF(core!$H29="EURO";core!$K29*core!$N$3/core!$N$2+core!$K29*core!$N$3/core!$N$2*core!$F29+core!$K29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=2;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$K29/core!$N$3+core!$K29/core!$N$3*core!$F29+core!$K29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$K29*core!$N$2/core!$N$3+core!$K29*core!$N$2/core!$N$3*core!$F$29+core!$K29*core!$N$2/core!$N$3*core!$g$29;IF(core!$H29="EURO";core!$K29+core!$K29*core!$F29+core!$K29*core!$g29;"")))))))))));
IF(core!$D$11=3;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$M29+core!$M29*core!$F29+core!$M29*core!$g29;IF(core!$H29="USD";core!$M29*core!$N$2+core!$M29*core!$N$2*core!$F29+core!$M29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$M29*core!$N$3+core!$M29*core!$N$3*core!$F29+core!$M29*core!$N$3*core!$g29;"")));
IF(core!$D$11=3;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$M29/core!$N$2+core!$M29/core!$N$2*core!$F29+core!$M29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$M29+core!$M29*core!$F29+core!$M29*core!$g29;IF(core!$H29="EURO";core!$M29*core!$N$3/core!$N$2+core!$M29*core!$N$3/core!$N$2*core!$F29+core!$M29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=3;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$M29/core!$N$3+core!$M29/core!$N$3*core!$F29+core!$M29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$M29*core!$N$2/core!$N$3+core!$M29*core!$N$2/core!$N$3*core!$F29+core!$M29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$M29+core!$M29*core!$F29+core!$M29*core!$g29;"")))))))))));
IF(core!$D$11=4;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$O29+core!$O29*core!$F29+core!$O29*core!$g29;IF(core!$H29="USD";core!$O29*core!$N$2+core!$O29*core!$N$2*core!$F29+core!$O29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$O29*core!$N$3+core!$O29*core!$N$3*core!$F29+core!$O29*core!$N$3*core!$g29;"")));
IF(core!$D$11=4;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$O29/core!$N$2+core!$O29/core!$N$2*core!$F29+core!$O29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$O29+core!$O29*core!$F29+core!$O29*core!$g29;IF(core!$H29="EURO";core!$O29*core!$N$3/core!$N$2+core!$O29*core!$N$3/core!$N$2*core!$F29+core!$O29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=4;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$O29/core!$N$3+core!$O29/core!$N$3*core!$F29+core!$O29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$O29*core!$N$2/core!$N$3+core!$O29*core!$N$2/core!$N$3*core!$F29+core!$O29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$O29+core!$O29*core!$F29+core!$O29*core!$g29;"")))))))))));
IF(core!$D$11=5;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$Q29+core!$Q29*core!$F29+core!$Q29*core!$g29;IF(core!$H29="USD";core!$Q29*core!$N$2+core!$Q29*core!$N$2*core!$F29+core!$Q29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$Q29*core!$N$3+core!$Q29*core!$N$3*core!$F29+core!$Q29*core!$N$3*core!$g29;"")));
IF(core!$D$11=5;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$Q29/core!$N$2+core!$Q29/core!$N$2*core!$F29+core!$Q29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$Q29+core!$Q29*core!$F29+core!$Q29*core!$g29;IF(core!$H29="EURO";core!$Q29*core!$N$3/core!$N$2+core!$Q29*core!$N$3/core!$N$2*core!$F29+core!$Q29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=5;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$Q29/core!$N$3+core!$Q29/core!$N$3*core!$F29+core!$Q29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$Q29*core!$N$2/core!$N$3+core!$Q29*core!$N$2/core!$N$3*core!$F29+core!$Q29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$Q29+core!$Q29*core!$F29+core!$Q29*core!$g29;"")))))))))));
IF(core!$D$11=6;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$S29+core!$S29*core!$F29+core!$S29*core!$g29;IF(core!$H29="USD";core!$S29*core!$N$2+core!$S29*core!$N$2*core!$F29+core!$S29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$S29*core!$N$3+core!$S29*core!$N$3*core!$F29+core!$S29*core!$N$3*core!$g29;"")));
IF(core!$D$11=6;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$S29/core!$N$2+core!$S29/core!$N$2*core!$F29+core!$S29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$S29+core!$S29*core!$F29+core!$S29*core!$g29;IF(core!$H29="EURO";core!$S29*core!$N$3/core!$N$2+core!$S29*core!$N$3/core!$N$2*core!$F29+core!$S29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=6;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$S29/core!$N$3+core!$S29/core!$N$3*core!$F29+core!$S29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$S29*core!$N$2/core!$N$3+core!$S29*core!$N$2/core!$N$3*core!$F29+core!$S29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$S29+core!$S29*core!$F29+core!$S29*core!$g29;"")))))))))));
IF(core!$D$11=7;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$U29+core!$U29*core!$F29+core!$U29*core!$g29;IF(core!$H29="USD";core!$U29*core!$N$2+core!$U29*core!$N$2*core!$F29+core!$U29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$U29*core!$N$3+core!$U29*core!$N$3*core!$F29+core!$U29*core!$N$3*core!$g29;"")));
IF(core!$D$11=7;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$U29/core!$N$2+core!$U29/core!$N$2*core!$F29+core!$U29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$U29+core!$U29*core!$F29+core!$U29*core!$g29;IF(core!$H29="EURO";core!$U29*core!$N$3/core!$N$2+core!$U29*core!$N$3/core!$N$2*core!$F29+core!$U29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=7;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$U29/core!$N$3+core!$U29/core!$N$3*core!$F29+core!$U29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$U29*core!$N$2/core!$N$3+core!$U29*core!$N$2/core!$N$3*core!$F29+core!$U29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$U29+core!$U29*core!$F29+core!$U29*core!$g29;"")))))))))));
IF(core!$D$11=8;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$W29+core!$W29*core!$F29++core!$W29*core!$g29;IF(core!$H29="USD";core!$W29*core!$N$2+core!$W29*core!$N$2*core!$F29+core!$W29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$W29*core!$N$3+core!$W29*core!$N$3*core!$F29+core!$W29*core!$N$3*core!$g29;"")));
IF(core!$D$11=8;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$W29/core!$N$2+core!$W29/core!$N$2*core!$F29+core!$W29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$W29+core!$W29*core!$F29+core!$W29*core!$g29;IF(core!$H29="EURO";core!$W29*core!$N$3/core!$N$2+core!$W29*core!$N$3/core!$N$2*core!$F29+core!$W29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=8;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$W29/core!$N$3+core!$W29/core!$N$3*core!$F29+core!$W29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$W29*core!$N$2/core!$N$3+core!$W29*core!$N$2/core!$N$3*core!$F29+core!$W29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$W29+core!$W29*core!$F29+core!$W29*core!$g29;"")))))))))));
IF(core!$D$11=9;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$Y29+core!$Y29*core!$F29+core!$Y29*core!$g29;IF(core!$H29="USD";core!$Y29*core!$N$2+core!$Y29*core!$N$2*core!$F29+core!$Y29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$Y29*core!$N$3+core!$Y29*core!$N$3*core!$F29+core!$Y29*core!$N$3*core!$g29;"")));
IF(core!$D$11=9;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$Y29/core!$N$2+core!$Y29/core!$N$2*core!$F29+core!$Y29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$Y29+core!$Y29*core!$F29+core!$Y29*core!$g29;IF(core!$H29="EURO";core!$Y29*core!$N$3/core!$N$2+core!$Y29*core!$N$3/core!$N$2*core!$F29+core!$Y29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=9;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$Y29/core!$N$3+core!$Y29/core!$N$3*core!$F29+core!$Y29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$Y29*core!$N$2/core!$N$3+core!$Y29*core!$N$2/core!$N$3*core!$F29+core!$Y29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$Y29+core!$Y29*core!$F29+core!$Y29*core!$g29;"")))))))))));
IF(core!$D$11=10;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$AA29+core!$AA29*core!$F29+core!$AA29*core!$g29;IF(core!$H29="USD";core!$AA29*core!$N$2+core!$AA29*core!$N$2*core!$F29+core!$AA29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$AA29*core!$N$3+core!$AA29*core!$N$3*core!$F29+core!$AA29*core!$N$3*core!$g29;"")));
IF(core!$D$11=10;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$AA29/core!$N$2+core!$AA29/core!$N$2*core!$F29+core!$AA29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$AA29+core!$AA29*core!$F29+core!$AA29*core!$g29;IF(core!$H29="EURO";core!$AA29*core!$N$3/core!$N$2+core!$AA29*core!$N$3/core!$N$2*core!$F29+core!$AA29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=10;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$AA29/core!$N$3+core!$AA29/core!$N$3*core!$F29+core!$AA29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$AA29*core!$N$2/core!$N$3+core!$AA29*core!$N$2/core!$N$3*core!$F29+core!$AA29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$AA29+core!$AA29*core!$F29+core!$AA29*core!$g29;""))))))))))))))))))))
*(core!$G29+1))
enter image description here
The IFERROR has the format IFERROR(Value, Value_if_error). Your Value is this:
IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="TL";IF(core!$H29="TL";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="USD";core!$I29*core!$N$2+core!$I29*core!$N$2*core!$F29+core!$I29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3+core!$I29*core!$N$3*core!$F29+core!$I29*core!$N$3*core!$g29;"")));IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$I29/core!$N$2+core!$I29/core!$N$2*core!$F29+core!$I29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3/core!$N$2+core!$I29*core!$N$3/core!$N$2*core!$F29+core!$I29*core!$N$3/core!$N$2*core!$g29;"")));IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";(core!$I29/core!$N$3+core!$I29/core!$N$3*core!$F29+core!$I29/core!$N$3*core!$g29);IF(core!$H29="USD";(core!$I29*core!$N$2/core!$N$3+core!$I29*core!$N$2/core!$N$3*core!$F29+core!$I29*core!$N$2/core!$N$3*core!$g29);IF(core!$H29="EURO";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;""))))))))))));
Taking your formula, splitting out the first part of the IFERROR, and eliminating the spurious code (i.e. IF(A=1, IF(B=2, IF(A=1, ALWAYS_TRUE, ALWAYS_FALSE), C), D) is functionally identical to IF(A=1, IF(B=2, ALWAYS_TRUE, C), D)), I then built the following table:
The Red, Blue and Green text are Common Terms, present in every formula.
Examining this, and rearranging it slightly, I spot the following patterns:
When D7 is "USD", Divide by $N$2
When D7 is "EURO", Divide by $N$3
When H29 is "USD", Multiply by $N$2
When H29 is "EURO", Multiply by $N$3
Implicitly, the following rules also exist:
When D7 is "TL", Divide by 1
When H29 is "TL", Multiply by 1
I can use a VLOOKUP to pick which cells to use, resulting in the form VLOOKUP(H29,..) * (Common_Terms) / VLOOKUP(D7,..)
This allows me to rewrite your Value as follows:
IF(AND(core!$D$11=1,$F15>0), IF(AND(MATCH(core!$D$11,{"TL","USD","EURO","*"},0)<4, MATCH(core!$H$29,{"TL","USD","EURO","*"},0)<4), VLOOKUP(core!H$29,{"USD",core!$N$2;"Euro",core!$N$3;"TL",1},2,FALSE)*(core!$I29 + core!$I29*core!$F29 + core!$I29*core!$g29)/VLOOKUP(core!H$29,{"USD",core!$N$2;"Euro",core!$N$3;"TL",1},2,FALSE), ""), FALSE)
Which is a third of the length. You should be able to manage similar optimisation of almost every IF condition you have.
More importantly, a lot of your repeated (and unnecessary) IF conditions are checking if H29 and D7 are "TL"/"USD"/"EUR", or checking that F15>0. You can eliminate these by making your outermost IF statement look like this:
=IF(AND($F15>0, MATCH(core!$D$7, core!$D$11, {"TL","USD","EURO","*"},0)<4, MATCH(core!$H$29, {"TL","USD","EURO","*"},0)<4), ALL_THREE_CONTITIONS_ARE_TRUE, "")
I am looking to come up with a crafty and "nice-looking" way of rounding to the nearest NON-ZERO whole number (I will only ever have positive integers). Three restraints I have are:
Must be a non-UDF solution as I will have some users who will want to trace formulas. Even though a VBA solution will result in a cleaner entry in the formula bar, they are not easily traceable by "front-end" users.
Some of the cells I am looking to round are quite long formulas themselves.
Think something like =(SUMPRODUCT((A1:A20),(B1:B20)) / SUMPRODUCT((A21:A40),(B21:B40))) - (SUMPRODUCT((A41:A60),(B41:B60)) * SUMPRODUCT((A61:A80),(B61:B80))) + SUMPRODUCT((A81:A100),(B81:B100))
I am unable to round the values in A1:B100 to make it whole numbers to begin with.
I am unable to use the cells with my formulas as a reference due to how the sheet must be styled for users. (e.g. I can only have one column of visible cells with my results. Therefore, if I used the formula cells as a reference, the formula cells would have to be hidden. This breaks restraint #1 because users would have difficulty with formula tracing.) This restraint is described in more detail below.
The most succinct formula I can think of is thus:
=IF(AND(C1 > 0, C1 < 1), ROUNDUP(C1, 0), ROUND(C1, 0))
Due to #3, I cannot use C1 as a reference. So my end result would be more like:
=IF(AND((SUMPRODUCT((A1:A20),(B1:B20)) / SUMPRODUCT((A21:A40),(B21:B40))) - (SUMPRODUCT((A41:A60),(B41:B60)) * SUMPRODUCT((A61:A80),(B61:B80))) + SUMPRODUCT((A81:A100),(B81:B100)) > 0, (SUMPRODUCT((A1:A20),(B1:B20)) / SUMPRODUCT((A21:A40),(B21:B40))) - (SUMPRODUCT((A41:A60),(B41:B60)) * SUMPRODUCT((A61:A80),(B61:B80))) + SUMPRODUCT((A81:A100),(B81:B100)) < 1), ROUNDUP((SUMPRODUCT((A1:A20),(B1:B20)) / SUMPRODUCT((A21:A40),(B21:B40))) - (SUMPRODUCT((A41:A60),(B41:B60)) * SUMPRODUCT((A61:A80),(B61:B80))) + SUMPRODUCT((A81:A100),(B81:B100)), 0), ROUND((SUMPRODUCT((A1:A20),(B1:B20)) / SUMPRODUCT((A21:A40),(B21:B40))) - (SUMPRODUCT((A41:A60),(B41:B60)) * SUMPRODUCT((A61:A80),(B61:B80))) + SUMPRODUCT((A81:A100),(B81:B100)), 0))
Not very "nice-looking".
Any recommendations?
EDIT Overly complex formulas removed
Another, simpler option
=MAX(1,ROUND(your_formula,0))
My formula assumes that your_formula will only return a positive value. If that is not the case, please clarify what results you expect for zero or negative results.
EDIT
With regard to possible zero values, try this. I cannot test it since I am not at computer:
=--(TEXT(your_formula, "[>1]0;[>0]1;0"))
Except for negatives (of which there aren't any) this formula:
=(C1<>0)*IF(C1<1,1,ROUND(C1,0))
produces the same results as:
=IF(AND(C1>0,C1<1),ROUNDUP(C1,0),ROUND(C1,0))
and is 15 characters shorter.
It deals with 0 with (C1<>0) by returning FALSE when C1 is zero, which the * effectively converts to 0. Otherwise TRUE and then by multiplying by 1 instead of 0 it does not affect the result of the rest of the formula.
The IF statement then tests whether or not C1 is less than 1. If so, returns 1 and otherwise applies standard rounding (to integers).
The formula might be shortened if the output range were formatted with Cells Format but otherwise anything more succinct is quite likely to be less intelligible - and may be more a matter for Programming Puzzles & Code Golf than SO.
Though:
=--(TEXT(C1,"[>1]0;[>0]1;0"))
is indeed 4 characters shorter still.
I'm making a spreadsheet in excel to help me understand how starting a part-time business on top of my full time job might affect my tax. I need to do this because I'm very close to my next UK tax bracket and I want to know exactly how it might affect my finances.
As part of this I'm trying to write an excel formula that will add two numbers then check if this new number is greater than a third number. I will refer to the two numbers added together as A and the third number as B. If A is not greater than B then I will multiply by 20% to find out how much of it is owed in tax. If A is greater than B I will subtract B from A to create number C and multiply B by 20% and C by 40% and add the two together to produce the final number I need. Can someone please xplain to me how to script this in Excel? I've looked for online examples but I'm not finding the language very penetrable. If I was using a scripting language I was more familiar with the code would look like this:
float taxThreshold = 42011.00;
int income = foo;
if(taxThreshold < income)
{
float higherRate = income-taxThreshold;
float standardTaxOwed = taxThreshold * 20%;
float higherRateOwed = higherRate * 40%;
float finalTaxOwed = standardTaxOwed+higherTaxOwed;
}
else
{
float finalTaxOwed = income * 20%;
}
I'm sure this is very simple to do, I just don't get the excel syntax. Can someone show me how this should be done? You'd not only be solving this problem but also giving me a means of translating from my current scripting knowledge into excel.
The easiest way is to store your 4 input parameters in some cells - and then name them. To do so, select the cell and type a meaningful name into the field that shows the address (i.e. left of the formula bar).
Once you have done this, you can simply use this formula:
=IF(Income>Threshold,Threshold*StandardTaxRate+(Income-Threshold)*HighTaxRate,Income*StandardTaxRate)
Without the naming, the formula would be something like this:
=IF(B2>B1,B1*B7+(B2-B1)*B8,B2*B7)
Both formulas will calculate you the tax you'd need to pay. If you want it more explicit, I'd recommend a layout such as this:
The formulas would read:
C7: =IF(B2>B1,B1,B2)
C8: =IF(B2>B1,B2-B1,0)
D7: =B7*C7
D8: =B8*C8
HTH!
I have an interesting challenge - I need to run a check on the following data in Excel:
| A - B - C - D |
|------|------|------|------|
| 36 | 0 | 0 | x |
| 0 | 600 | 700 | x |
|___________________________|
You'll have to excuse my wonderfully bad ASCII art. So I need the D column (x) to run a check against the adjacent cells, then convert the values if necessary. Here's the criteria:
If column B is greater than 0, everything works great and I can get coffee. If it doesn't meet that requirement, then I need to convert A1 according to a table - for example, 32 = 1420 and place into D. Unfortunately, there is no relationship between A and what it needs to convert to, so creating a calculation is out of the question.
A case or switch statement would be perfect in this scenario, but I don't think it is a native function in Excel. I also think it would be kind of crazy to chain a bunch of =IF() statements together, which I did about four times before deciding it was a bad idea (story of my life).
Sounds like a job for VLOOKUP!
You can put your 32 -> 1420 type mappings in a couple of columns somewhere, then use the VLOOKUP function to perform the lookup.
Without reference to the original problem (which I suspect is long since solved), I very recently discovered a neat trick that makes the Choose function work exactly like a select case statement without any need to modify data. There's only one catch: only one of your choose conditions can be true at any one time.
The syntax is as follows:
CHOOSE(
(1 * (CONDITION_1)) + (2 * (CONDITION_2)) + ... + (N * (CONDITION_N)),
RESULT_1, RESULT_2, ... , RESULT_N
)
On the assumption that only one of the conditions 1 to N will be true, everything else is 0, meaning the numeric value will correspond to the appropriate result.
If you are not 100% certain that all conditions are mutually exclusive, you might prefer something like:
CHOOSE(
(1 * TEST1) + (2 * TEST2) + (4 * TEST3) + (8 * TEST4) ... (2^N * TESTN)
OUT1, OUT2, , OUT3, , , , OUT4 , , <LOTS OF COMMAS> , OUT5
)
That said, if Excel has an upper limit on the number of arguments a function can take, you'd hit it pretty quickly.
Honestly, can't believe it's taken me years to work it out, but I haven't seen it before, so figured I'd leave it here to help others.
EDIT: Per comment below from #aTrusty:
Silly numbers of commas can be eliminated (and as a result, the choose statement would work for up to 254 cases) by using a formula of the following form:
CHOOSE(
1 + LOG(1 + (2*TEST1) + (4*TEST2) + (8*TEST3) + (16*TEST4),2),
OTHERWISE, RESULT1, RESULT2, RESULT3, RESULT4
)
Note the second argument to the LOG clause, which puts it in base 2 and makes the whole thing work.
Edit: Per David's answer, there's now an actual switch statement if you're lucky enough to be working on office 2016. Aside from difficulty in reading, this also means you get the efficiency of switch, not just the behaviour!
The Switch function is now available, in Excel 2016 / Office 365
SWITCH(expression, value1, result1, [default or value2, result2],…[default or value3, result3])
example:
=SWITCH(A1,0,"FALSE",-1,"TRUE","Maybe")
Microsoft -Office Support
Note: MS has updated that page to only document the behavior of Excel 2019. Eventually, they will probably remove references to 2019 as well... To see what the page looked like in 2016, use the wayback machine:
https://web.archive.org/web/20161010180642/https://support.office.com/en-us/article/SWITCH-function-47ab33c0-28ce-4530-8a45-d532ec4aa25e
Try this;
=IF(B1>=0, B1, OFFSET($X$1, MATCH(B1, $X:$X, Z) - 1, Y)
WHERE
X = The columns you are indexing into
Y = The number of columns to the left (-Y) or right (Y) of the indexed column to get the value you are looking for
Z = 0 if exact-match (if you want to handle errors)
I used this solution to convert single letter color codes into their descriptions:
=CHOOSE(FIND(H5,"GYR"),"Good","OK","Bad")
You basically look up the element you're trying to decode in the array, then use CHOOSE() to pick the associated item. It's a little more compact than building a table for VLOOKUP().
I know it a little late to answer but I think this short video will help you a lot.
http://www.xlninja.com/2012/07/25/excel-choose-function-explained/
Essentially it is using the choose function. He explains it very well in the video so I'll let do it instead of typing 20 pages.
Another video of his explains how to use data validation to populate a drop down which you can select from a limited range.
http://www.xlninja.com/2012/08/13/excel-data-validation-using-dependent-lists/
You could combine the two and use the value in the drop down as your index to the choose function. While he did not show how to combine them, I'm sure you could figure it out as his videos are good. If you have trouble, let me know and I'll update my answer to show you.
I understand that this is a response to an old post-
I like the If() function combined with Index()/Match():
=IF(B2>0,"x",INDEX($H$2:$I$9,MATCH(A2,$H$2:$H$9,0),2))
The if function compare what is in column b and if it is greater than 0, it returns x, if not it uses the array (table of information) identified by the Index() function and selected by Match() to return the value that a corresponds to.
The Index array has the absolute location set $H$2:$I$9 (the dollar signs) so that the place it points to will not change as the formula is copied. The row with the value that you want returned is identified by the Match() function. Match() has the added value of not needing a sorted list to look through that Vlookup() requires. Match() can find the value with a value: 1 less than, 0 exact, -1 greater than. I put a zero in after the absolute Match() array $H$2:$H$9 to find the exact match. For the column that value of the Index() array that one would like returned is entered. I entered a 2 because in my array the return value was in the second column. Below my index array looked like this:
32 1420
36 1650
40 1790
44 1860
55 2010
The value in your 'a' column to search for in the list is in the first column in my example and the corresponding value that is to be return is to the right. The look up/reference table can be on any tab in the work book - or even in another file. -Book2 is the file name, and Sheet2 is the 'other tab' name.
=IF(B2>0,"x",INDEX([Book2]Sheet2!$A$1:$B$8,MATCH(A2,[Book2]Sheet2!$A$1:$A$8,0),2))
If you do not want x return when the value of b is greater than zero delete the x for a 'blank'/null equivalent or maybe put a 0 - not sure what you would want there.
Below is beginning of the function with the x deleted.
=IF(B2>0,"",INDEX...
If you don't have a SWITCH statement in your Excel version (pre-Excel-2016), here's a VBA implementation for it:
Public Function SWITCH(ParamArray args() As Variant) As Variant
Dim i As Integer
Dim val As Variant
Dim tmp As Variant
If ((UBound(args) - LBound(args)) = 0) Or (((UBound(args) - LBound(args)) Mod 2 = 0)) Then
Error 450 'Invalid arguments
Else
val = args(LBound(args))
i = LBound(args) + 1
tmp = args(UBound(args))
While (i < UBound(args))
If val = args(i) Then
tmp = args(i + 1)
End If
i = i + 2
Wend
End If
SWITCH = tmp
End Function
It works exactly like expected, a drop-in replacement for example for Google Spreadsheet's SWITCH function.
Syntax:
=SWITCH(selector; [keyN; valueN;] ... defaultvalue)
where
selector is any expression that is compared to keys
key1, key2, ... are expressions that are compared to the selector
value1, value2, ... are values that are selected if the selector equals to the corresponding key (only)
defaultvalue is used if no key matches the selector
Examples:
=SWITCH("a";"?") returns "?"
=SWITCH("a";"a";"1";"?") returns "1"
=SWITCH("x";"a";"1";"?") returns "?"
=SWITCH("b";"a";"1";"b";TRUE;"?") returns TRUE
=SWITCH(7;7;1;7;2;0) returns 2
=SWITCH("a";"a";"1") returns #VALUE!
To use it, open your Excel, go to Develpment tools tab, click Visual Basic, rightclick on ThisWorkbook, choose Insert, then Module, finally copy the code into the editor. You have to save as a macro-friendly Excel workbook (xlsm).
Even if old, this seems to be a popular questions, so I'll post another solution, which I think is very elegant:
http://fiveminutelessons.com/learn-microsoft-excel/using-multiple-if-statements-excel
It's elegant because it uses just the IF function. Basically, it boils down to this:
if(condition, choose/use a value from the table, if(condition, choose/use another value from the table...
And so on
Works beautifully, even better than HLOOKUP or VLOOOKUP
but... Be warned - there is a limit to the number of nested if statements excel can handle.
Microsoft replace SWITCH, IFS and IFVALUES with CHOOSE only function.
=CHOOSE($L$1,"index_1","Index_2","Index_3")
Recently I unfortunately had to work with Excel 2010 again for a while and I missed the SWITCH function a lot. I came up with the following to try to minimize my pain:
=CHOOSE(SUM((A1={"a";"b";"c"})*ROW(INDIRECT(1&":"&3))),1,2,3)
CTRL+SHIFT+ENTER
where A1 is where your condition lies (it could be a formula, whatever). The good thing is that we just have to provide the condition once (just like SWITCH) and the cases (in this example: a,b,c) and results (in this example: 1,2,3) are ordered, which makes it easy to reason about.
Here is how it works:
Cond={"c1";"c2";...;"cn"} returns a N-vector of TRUE or FALSE (with behaves like 1s and 0s)
ROW(INDIRECT(1&":"&n)) returns a N-vector of ordered numbers: 1;2;3;...;n
The multiplication of both vectors will return lots of zeros and a number (position) where the condition was matched
SUM just transforms this vector with zeros and a position into just a single number, which CHOOSE then can use
If you want to add another condition, just remember to increment the last number inside INDIRECT
If you want an ELSE case, just wrap it inside an IFERROR formula
The formula will not behave properly if you provide the same condition more than once, but I guess nobody would want to do that anyway
If your using Office 2016 or later, or Office 365, there is a new function that acts similarly to a CASE function called IFS. Here's the description of the function from Microsoft's documentation:
The IFS function checks whether one or more conditions are met, and returns a value that corresponds to the first TRUE condition. IFS can take the place of multiple nested IF statements, and is much easier to read with multiple conditions.
An example of usage follows:
=IFS(A2>89,"A",A2>79,"B",A2>69,"C",A2>59,"D",TRUE,"F")
You can even specify a default result:
To specify a default result, enter TRUE for your final logical_test argument. If none of the other conditions are met, the corresponding value will be returned.
The default result feature is included in the example shown above.
You can read more about it on Microsoft's Support Documentation