I am trying to build a complicated spreadsheet and I need a statement to do the following:
If C2=R2 and D2 is < T2 then U2, if D2 is >T but T3 but < T4 then U4 if D2 is > T4 but < T5 then U5, if D2 is > T5 but < T6 then U6 BUT if C2 does not equal R2 then S8
I think it needs to be some sort of IF statement, but i am tearing my hair out.
UPDATE:
Vicky's formula almost worked. I have jigged it a bit and it now looks like this.
=IF(C6=$R$3,IF(D6<=0.99,$U$2,IF(AND(D6>0.99,D6<=4.99),$U$3,IF(AND(D6>4.99,D6<=14.99),$U$4,IF(AND(D6>14.99,D3<=29.99),$U$5,IF(AND(D6>29.99,D6<99.99),$U$6,""))))),$S$8)
It all works fine until you change the value in cell D6 to say £45 when it still picks up the figure in cell U5. What do I need to tweak to fix that?
Here you go:
=IF(C2=R2, IF(D2<T2, U2, IF(AND(D2>T3, D2<T4), U4, IF(AND(D2>T4, D2<T5), U5, IF(AND(D2>T5, D2<T6), U6, "")))), S8)
Note that I am assuming that "if D2 is >T but T3 but < T4" is a typo for "if D2 is >T3 but < T4" and that if C2=R2 but D2 is not in any of the other ranges you just want the cell left blank.
IF(AND(D6>14.99,D3<=29.99)
you've got a reference to D3 here not D6.
Yes, this would normally be expressed as an IF statement.
You could write this as one long complicated set of nested IF statements in your spreadsheet or you could write it in VBA. The VBA option would be easier to comprehend and therefore easier to maintain, but it would be a slightly steeper learning curve.
Try throwing in an ARRAY if you are trying to settle items in the same row.
What you're after is a VLOOKUP, combined with an IF
=IF(C2=R2, VLOOKUP(D2, T2:U6, 2, TRUE), S8)
This says:
If C2 = R2
find the first row in T2:U6 where the value in the first column is greater than D2
return the value in the second column from that row
otherwise return S8.
Which is equivalent to your initial criteria.
Related
I am having some trouble with my if statement, join with and and or. Could someone tell me why the selected cell is not returning the value of 2? It returns "" even though it is between 6.5 and 6.0. The other problem I am running into is when I format column R to have one decimal place, the selected cell should result in 1.
Column S equation: =IF(AND(R2<=H2+0.5,R2>=H2-0.5),1,"")
Column T equation: =IF(AND(OR(AND(R3<=H3+1,R3>H3+0.5),R3>=H3-1),R3<H3-0.5),2,"")
Column U equation: =IF(OR(S2=1,T2=2),"",3)
The goal of this is to determine how far R3 falls from H3 based on set thresholds. The thresholds are +-0.5, +-1, and outside +-1. For example R3 is larger than H3 + 0.5 and less than or equal to H3 + 1. So T3 should result with a 2.
My formula for T3:
=IF(ABS(H3-R3)>1,"difference > 1",IF(ABS(H3-R3)>=0.5,"difference between 1 and 0.5","difference < 0.5"))
This VBA code will write you the formula on a selected cell in the T column:
ActiveCell.FormulaR1C1 = "=IF(ABS(RC[-1]-RC[-11])>1,""difference > 1"",IF(ABS(RC[-1]-RC[-11])>=0.5,""difference between 1 and 0.5"",""difference < 0.5""))"
You can change the text with numbers as pleased. Does this satisfy you?
I just tried this and it worked for me:
=IF(AND(R3<=H3+1,R3>H3+0.5),2,IF(AND(R3>=H3-1,R3<H3-0.5),2,""))
I think this works for you in a single formula.
Formula in C1 and down is
=LOOKUP(ABS(B1-A1),{0,0.5,1},{1,2,3})
Ok, so I am trying to do something I thought was very simple, but it is turning out to be more complicated.
What I am trying to do:
Take a value through an if statement and return 1 or 0. But I want to be able to change the formula by changing values in cells and not editing the formula itself.
Example:
cell A1 = 41%
cell B1 = >
cell C1 = 40%
cell D1 = Formula with calculation
I want to create a formula that will tell me if that 41% is > than 40%, but if I change that > in B1 for a < (in a separate cell outside the cell with the formula) or I change C1 I want it to recalculate.
I have tried the following:
=IF(A1&B1&C1,1,0)
=IF(A1&INDIRECT(B1)&C1,1,0)
=IF(INDIRECT(A1)&INDIRECT(B1)&INDIRECT(C1),1,0)
all of these result in errors and I cannot figure out how to make it work. I am assuming it is taking the > and making it a string instead of a part of the formula.
Thanks for the help.
=COUNTIF( A1, B1&C1 )
... seems to do the trick, although converting C1 to text may give some rounding errors
An alternative would of course be to enumerate all the operations:
=--IFS( B1=">", A1>C1, B1="<", A1<C1 )
And add other operators as you come across them (NB the -- turns TRUE/FALSE into 1/0)
My initial question was answered here:
Looking up a value in a range that is between two given values
But when trying to achieve the same result with more data rows than just one, I am struggling. Here is a screen shot :
So, if I type 542515 in, it needs to look at P5 and P6 / Q5 and Q6
and see that 542515 is job 8584 and therefore in the output it must show 8584. If I input between 544360 and 544400 then it needs to output 8586.
Hope this makes sense!
If your ranges in columns P and Q do not overlap, then you can simply check the input value in N5 against each range using an IF formula. My IF formula defaults to a value of 0 if the input cannot be found in the range. Then I SUM over the O column to find the job which matched.
Formula in O5:
=IF(AND(N$5 > P5, N$5 < Q5), M5, 0)
Formula in O6:
=IF(AND(N$5 > P6, N$5 < Q6), M6, 0)
Formula in O8:
=SUM(O5:O6)
you can use SUMIFS formula if the ranges does not overlap
Example considering 544370 is mentioned in N3 cell
O3=SUMIFS(M:M,P:P,"<="&N3,Q:Q,">="&N3)
For non-numeric job value try this
=INDEX(M:M,SUMPRODUCT(--(P:P<=N3),--(Q:Q>=N3),ROW(A:A)))
I am trying to write the following function in Excel.
if P2 is greater than or equal to 3 and AD2 is 0
OR
if P2 is greater than or equal to 2 and AD2 is greater than or equal to 1
OR
if P2 is greater than or equal to 1 and AD2 is 2
Then do the following:
(H2+V2)/(P2+AD2),-999)
I have had a go at writing the following to no avail.
=IF(AND(P2>=3,AD2>=0),OR(AND(P2>=2,AD2>=1)),OR(AND(P2>=1,AD2>=2)),(H2+V2)/(P2+AD2),-999)
Any pointers in the right direction would be much appreciated as I am a novice at Excel functions.
Many thanks,
Ash
Erm...
I think this is right:
=IF(OR(AND(P2>=3,AD2=0),AND(P2>=2,AD2>=1),AND(P2>=1,AD2=2)),(H2+V2)/(P2+AD2),-999)
You need to nest your different AND conditions within a OR function...
Easiest way to do it, is to have your seperate functions in a cell each and build it up a step at a time, until you're sure it's right.. Then you can paste the function into one cell if required.
Say the below are in Cells A1, A2, A3
=AND(P2>=3,AD2=0)
=AND(P2>=2,AD2>=1)
=AND(P2>=1,AD2=2)
Then your total formula in a cell:
=IF(OR(A1,A2,A3),(H2+V2)/(P2+AD2),-999)
Try this one:
=IF(OR(
AND(P2>=3,AD2>=0),
AND(P2>=2,AD2>=1),
AND(P2>=1,AD2>=2)
),
(H2+V2)/(P2+AD2),-999)
it's slightly unclear from your question what'd be the correct
AND(P2>=3,AD2>=0) and AND(P2>=1,AD2>=2)
or
AND(P2>=3,AD2=0) and AND(P2>=1,AD2=2)
but you can easily modify this behaviour in the formula above.
I have a row that will have weekly values entered. Column B has the initial value, and E has the calculation; as I add values to C, D and so on, I want the calculation to skip the previous columns value when the next column gets a value.
B1-C1=E1 BUT when a value is added to D1, E1 would update to B1-D1=E1
Sorry for the horrible description. This is probably answered somewhere on this site but I am not sure what terms to search.
Many thanks!
you can use an if statement. I am not 100% sure of your problem but something like this might be helpful.
if(A1, A1, 0)
So for your example provided.
=B1-if(D1, D1, C1)
This says if there is a value in D1 use D1 else use C1. This works in this example, because if
D1 is empty or 0 you will use the other cell. This may change for any given problem.
Use this if function in E1:
=IF(D1>0,B1-D1,IF(C1>0,B1-C1,B1))
Then enter a value in B1, then C1 then D1 to see the results.
According to your question, you only have room for two entries after the default B1 value. This statement will handle that.
If you need more fields, nest more if functions. But if's can only be nested 7 deep, so you can only have an initial value in B1 and 7 more cells, C1 to I1 with your formula in J1
If you actual data is as simple as your sample data you could just use:
=IF(LEN(D2)>0, B2-D2,B2-C2)
You could also use:
=IF(ISBLANK(D2), B2-C2, B2-D2)
if you prefer but Len is a little shorter and I believe the ISBLANK() function has flaws, If you have a formula in D2 that has a calculation and you set the result to "" then it will pick up as false. It depends on your needs.
I would do the following.
In E1 paste the following:
=A1-INDEX(B1:D1,1,COUNT(B1:D1))
The count formula will tell how many values are present in the range of B:D column. This will be used to catch the last column with an index formula which will be deducted form A1.
One thing is very important! The values from A to D has to be written in sequence, if one column is missing than the calculation will be false.
Hope I could help!