Get the UIEdgeInsets from subtracting 2 CGRects - geometry

I have a CGRect "A" contained in another CGRect "B"
I'm not sure on how UIEdgeInsets are calculated - and I keep getting the arithmatic wrong - what I need is the edge insets (= "EI") such that "A" will be equal to "B" after performing:
UIEdgeInsetsRect("A","EI") == "B"
Is there a macro such that
"EI" = UIEdgeInsetsFromRects("B","A") ?
Thanks

Related

Automatic numbering in Excel with hierarchy

I would like to do an automatic summary numbering. The only thing we could do is to number the A's (the titles) but the subtitles should be numbered automatically. If the title = 1, subtitle 1.1, below 1.1.1 and so on.
Let's say the titles are A, B and C are subtibles.
The pattern should be like this
1.A
1.1 B
1.2 B
2.A
2.1 B
2.1.1 C
So I tried this : https://stackoverflow.com/a/32321112/7968011
What I get
What we want
What we want
If you have your Level Marker as "A" / "B" / "C" in Column A, and the heading in Column B, then you can use the following (convoluted) code:
=REPT(CHAR(9), CODE(A1)-65) & SUMPRODUCT(--(A:A="A")*--(ROW(A:A)<=ROW(A1))) & "." & IF(CODE(A1)>65,SUMPRODUCT(--(A:A="B")*--(ROW(A:A)<=ROW(A1))*--(ROW(A:A)>=MAX(--ROW(A:A)*--(A:A="A")*--(ROW(A:A)<=ROW(A1))))) & ".","") & IF(CODE(A1)>66,SUMPRODUCT(--(A:A="C")*--(ROW(A:A)<=ROW(A1))*--(ROW(A:A)>=MAX(--ROW(A:A)*--(A:A="B")*--(ROW(A:A)<=ROW(A1))))) & ".","") & CHAR(9) & B1
Let's break it down into steps:
Start with Tabs to indent the heading (0 for "A", 1 for "B", 2 for "C"): REPT(CHAR(9), CODE(A1)-65) where Char(9) is a Tab.
Next, we want to count how many "A"s have we had. We can use SUMPRODUCT to run this as an Array Formula, looking for cells where the value is "A" and the Row is <= current row: SUMPRODUCT(--(A:A="A")*--(ROW(A:A)<=ROW(A1))). Shove a dot after that, and you have your heading number.
Next, IF Column A is "B" or later in the alphabet (IF(CODE(A1)>65, since CODE("A")=65, CODE("B")=66, etc) then we want to count how many "B"s since the last "A". This is very similar to our last query, but we need a ROW(A:A)>=LAST_A. But, what is LAST_A? Well, we want the MAX Row where Column A = "A" and Row <= current row. So, MAX(--ROW(A:A)*--(A:A="A")*--(ROW(A:A)<=ROW(A1))).
This gives SUMPRODUCT(--(A:A="B")*--(ROW(A:A)<=ROW(A1))*--(ROW(A:A)>=MAX(--ROW(A:A)*--(A:A="A")*--(ROW(A:A)<=ROW(A1)))))
Now, we need to add the IF and the full-stop, to get
If(Code(A1)>65,SUMPRODUCT(--(A:A="B")*--(ROW(A:A)<=ROW(A1))*--(Row(A:A)>=MAX(--ROW(A:A)*--(A:A="A")*--(ROW(A:A)<=ROW(A1))))) & ".","")
Repeat the same for all "C"s since the last "B", and then finally add a Tab (CHAR(9)) and the value in Column B.
(If you want, for example, 4 spaces or 6 hyphens or 7 dots instead of Tabs at the start of the row or between the number and the tile, just replace the first or last CHAR(9))
{EDIT} Example:
Fast and dirty.
Just enter the first section manualy.
Then insert it below:
=IF(A3="down",B2&"1.",IF(A3="up",LEFT(B2,LEN(B2)-4)&MID(B2,LEN(B2)-3,1)+1&".",LEFT(B2,LEN(B2)-2)&MID(B2,LEN(B2)-1,1)+1&"."))
When you write "down" it will add "1." in the end of the string above.
When you write "up" it will remove the last 2 chars and add 1 to the last char of the string above.
if you dont write nothing it will add 1 to the last char.
bug: "up" will not work if section is > 9.

IF statement is giving the wrong results in excel

I am trying to get the 'delivery today?' column to reflect either Y or N. When column M is 0, I want it to reflect N and when column M is not O to reflect Y.
I have tried =IF(L15=0;"N";"Y"), this results in a circular reference or give an opposing result. I am not sure what else to try.
Thank you.
About the circular reference, I have two questions:
Does the value of L15 depends directly on the value of M15 (i.e., L = IF( M15 = "Y", do this, no that)?
Does the value of L15 depends indirectly on the value of M15 (i.e., L = N+P, but N = IF( M15 = "Y", do this, no that)?
If none of the questions are yes, it should never give you a circular reference at all. If it happens, means there is a dependency.
Now, about giving the opposite result, I can see in your formula:
=IF(L15=0;"N";"Y"), so: if L15 is equal to 0, M will get the value of "N".
Remember: `=IF(condition;value if true; else).
You can chose between two conditions:
L15 equal to 0, then: M15 = IF(L15=0;"Y";"N").
L15 different than 0, then: M15 = IF(L15<>0;"Y";"N").

How to use AND and OR function in excel to reach a decision

See the following image:
So, in this picture there are only 0s and 1s, and that is how it is setup.
Now, in the yellow box, where there is 1, I have put the condition as seen in the second yellow box. But, that is not the condition I want.
I want to check whether one or more cells for "A" are 1 or not. With that I also need to check whether one or more cells for "B" are 1 or not. If at least one cell in both "A" and "B" are 1, then write 1 otherwise write 0.
I hope that make sense. Thanks
Here is my suggestion:
=IF(AND(SUM(A3:A6)>0,SUM(B3:B6)>0),1,0)
You might want to name your ranges AList and BList. Then you could use:
=IF(AND(SUM(AList) >0,SUM(BList)>0),1,0)
Which makes it clearer what you're doing.
= IF( AND( OR(B3=1,B4=1,B5=1,B6=1), OR(C3=1,C4=1,C5=1,C6=1) ), "1", "0" )
is a bit long and not flexible if the range changes, but you can change it to array formula like this:
= IF( AND( OR(B3:B6 = 1), OR(C3:C6 = 1) ), "1", "0" )
and enter it with Ctrl + Shift + Enter

keeping a running sum of a formula with conditions

I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!
You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.
I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture

Trying to construct an IF statement in Excel with multiple conditions

Basically I need to calculate a column that sum's previous columns only if:
The number in column Q > 4,
Column S = 'N' (its a 'Y' or 'N' flag in this column and I only want to sum if there is an 'N'
P != 0 (There is a number in column P.)
This is the incorrect statement which I came up with:
=IF((Q2>4) AND (S2='N') AND (P2 != 0), V2)
(Column V contains the calculation I want to make, given that these conditions are met.
Kinda lost here guys, would really appreciate any help.
All the best.
EDIT: fixed single-quote>>double and != >> <>
=IF(AND(Q2>4, S2="N", P2<>0), V2, "")

Resources