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})
Related
Hi everyone I have the following excel table:
my task (performed in the green cell) is that for each year I compute the sum of the rows that contain a negative number in at least one of the previous years.
For instance the -1.29 in year two is the sum of the values in year to corresponding to rows 1,5,6,10,12 which are the rows containing negative numbers in the previous year. For year 3 same logic except that now I can sum all the values for that year from rows containing negative values either in Year 1 or Year 2.
for now in each of the green cells I am using the following formulas:
Year1 : 0
Year2 : =SUM(IF(B3:B13="-";0;B3:B13)($A$3:$A$13<0))
Year3 : =SUM(IF(C3:C13="-";0;C3:C13)((($B$3:$B$13<0)+($A$3:$A$13<0))>0))
Year4 : =SUM(IF(D3:D13="-";0;D3:D13)*((($C$3:$C$13<0)+($B$3:$B$13<0)+($A$3:$A$13<0))>0))
but I would like to make recursive, in the sense that I can just drag it to the next year without having to add one more of this ($C$3:$C$13<0) terms
would that be possible by just using Excel Formulas (hence no VBA)? An excel function computing the product of two vectors element by element would be enough but I cannot find anything like that unfortunately.
Hope to find some help!
Best,
Federico
Use MMULT:
=SUM(B2:B13*(MMULT(--($A$2:A13<0);TRANSPOSE(COLUMN($A$1:A1))^0)>0))
add formula to B14 and copy to the right. This is array formula.
If I understand you correctly, the following does what you want.
{=SUM(IF(A$1:A$13<0,B$1:B$13))}
Notes:
o The formula as shown is as it would be entered at B14
o Note the {}: This is an array formal so use Ctrl, Shift and Enter to enter the first case
o You don't need to eliminate text values (SUM does that automatically)
o I prefer to include headings (if they exist and are text) as it makes growing the table easier
Not sure why, but your example formulas started at row 3 (excluding row 2).
If that is truly what's wanted amend the above to:
{=SUM(IF(A$3:A$13<0,B$3:B$13))}
There is a quite simple solution in VBA:
Function getSum(rng As Range) As Variant
Dim r As Long, c As Long
For r = 1 To rng.Rows.Count
For c = 1 To rng.Columns.Count - 1
If rng.Cells(r, c) < 0 Then
getSum = getSum + rng.Cells(r, rng.Columns.Count)
Exit For
End If
Next
Next
End Function
Where the range passed to the function is written with a combination static/dynamic definition so the range expands. The upper left cell of the range will be the first cell of your data, static: say $A$3, and the lower right corner will be the bottom cell of the column with the values you are wanting to sum and dynamic, say: B14. In that case the formula =getSum($A$3:B14) would go in B15 and could be dragged over. Here's a picture:
I originally answered a different question than was asked. Currently editing to address the asked question using formulas only.
I've been trying to write a formula to summarise in one cell the presence/ absence of certain values in a different range of of cells in Excel
So in the one table and worksheet, I wrote
=IF(B1:F1=1,1,0) Formula 1
which is supposed to mean
If any of the values in cells B1:F1 are equal to 1, then note 1, otherwise not 0.
But somehow the syntax isn't working.
I've applied "" and ; and brackets right left and centre, but to no avail.
I'm pretty sure I done this before and it was pretty simple when I hit upon the right synstax, but the how and where fell through the colander which is my brain today :-?
Additionally I will want to ask the formula to apply another condition to the output cell which is
=if (A1 = value n or certain values, 1, 0) Formula2
Column A has numerically coded ordinal values 0-9, so an aexample of teh 1 conditions might be any of values 1, 2 or 9 in column, should produce a 1 in the result cell in which Formula 1 and 2 will be written.
So the result cell would contain somelike
=Formula1_or_Formula2_contain_certain_values, 1, 0) Formula 3
Obviously the systax of Formulas 2 and 3 is awol, but I write to demonostrate the formulae intended purposes.
The easiest way to make the first formula is like this:
=IF(SUM(B1:E1)>0,1,0)
No arrays, no problems :)
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'm a problem with one of my formula in excel. The formula is supposed to return the standard deviation of an range of cells if the value is not judged to be an outlier in another column.
My formula is STDAFV.S(HVIS(R2:R15<>"Outlier";P2:P15;""))
The problem is that it returns a wrong value. In the example below, the formula returns a wrong value of 0.010729, which should be 0.001652.
I'm well aware, that this is a array formula, thus I do press Ctrl+Shift+Enter. So this is not the issue!
Does anyone have a clue for what is wrong?
Col P | Col R
0.0215|
0.0207|
0.0233|
0.0213|
0.0187|
0.0917| Outlier
I get the same result as you when I am computing STDDEV across the 6 values of your OP including 7 empty cells as in your formula (P2:P15)
By doing so I add 7 times a value = 0 to the set which will affect the mean value and the divisor (N-1) in the STDDEV formula.
If I limit the range from row 2 to 7 ... the ones actually containing data, I get the result you're expecting.
Edit:
To circumvent the problem of empty cells without redefinig the range everytime you can make use of =COUNT() and =OFFSET() functions ...
Your values are placed in a growing list, but without empty cells between. So the number of cells (=rows) is the result of a =COUNT(B2:B1000)
Your effective data range now is "from B2 and [count result] cells down" ... i.e. =OFFSET(B2;0;0;COUNT(B2:B1000);1)
Likewise, your effective comment range now is "from C2 and [count result in B] cells down" ... i.e. =OFFSET(C2;0;0;COUNT(B2:B1000);1)
Combining all this ... with data in B2:B15 and remark in C2:C15, the array formula becomes
{ =STDEV.S(IF(OFFSET(C2;0;0;COUNT(B2:B15);1)<>"Outlier";OFFSET(B2;0;0;COUNT(B2:B15);1))) }
ta-taaaa!
I'm trying to get this programmed in Excel:
The variables you can change are Points and Steps. In the table there comes the value for each step until all the points/steps are given. The values beneath that has to be zero. I used the function Numbervalue to check some assumptions, but that didn't workout:
=IF(NUMBERVALUE(Previous_Cell) < POINTS;Previous_Cell+ POINTS_PER_CELL;0)
After the 2 points, the next cell becomes zero. But then the whole list starts over. So there has to be some function that says: If Previous_CELL = 0 then THIS_CELL = 0.
Assuming Points is in A1, in B6:
=IF(OR(SUM(B$5:B5)>B$2,B5=B$2),"",B$3*(MOD(ROW()-1,B$2)+1))
and in C6, with both copied down to suit:
=IF(OR(SUM(C$5:C5)>C$2,C5=C$2),"",C$3*(MOD(ROW()-6,C$2)+1))