Array formula does not change reference cells - excel

My Data:
I am trying to replicate the answer/formula from Column H. This is an array formula, so I committed it with Ctrl+Shift+Enter (C+S+E going forward).
My formula (in H2) is:
=MAX(IF(Sheet1!$X$3:$X$94=Sheet4!A2,Sheet1!$AI$3:$AI$94))
Columns I:L are different options I tried to replicate.
Column I: I highlighted the relevant cells, then put the above formula (from H2) in cell I2, and then used C+S+E. The result is 2 the entire way through.
Examining the differences between the formula between cells H5 and I5 shows that the reference "Sheet4!A2" is different.
In Column H, the cell reference is "Sheet4!A5", which is correct.
In I5, the reference is "Sheet4!A2, which is incorrect.
To get past this, I tried to write the formula in Column J, and drag it down, which resulted in all errors.
Columns K and L are instances where I tried typing in the formula, highlighting my range, and then pressing C+S+E, either by hand (Column K), or moving between sheets and highlighting relevant references (Column L). The same issue arose.
I even tried highlighting Column H, editing Cell H2, and the hit C+S+E. I got the same result as I did in Column I.
I looked at Excel Array Formula and Excel: Array Formula Calculates Once, but those suggestions did not help me in this instance.
Automatic calculation is on in my spreadsheet.

You need to understand that when you have selected more than one cell, enter a formula and confirm with CSE, it is totally different than having just one cell selected, enter the formula and CSE.
In your scenario, you want to select just one cell. Enter the formula, confirm with CSE, then copy the formula down. The references that are preceded with a $ sign will stay the same. The references without a $ sign will be adjusted when the formula is copied.
You may want to refresh you knowledge about relative and absolute reference, for example here

Related

Transferring certain cells from one sheet to another in excel despite column/row insertion/extraction

The title pretty much says it. I need to transfer certain cells from one cell to another without the coordinates of the cells changing after an insert operation.
In ex., I want the value of cell B3 of Sheet1 to transfer to cell A2 of Sheet2. If I insert a column on the left of B3, the previous B3 will become C3 and you now have a new B3 in which you can add a new value. I want my A2 to still receive the value of B3, but the new B3, not the old B3 with is now C3.
If I go with +Sheet1!B3, after the insertion of the column it will become +Sheet1!C3. I want it to remain to +Sheet1!B3.
I tried with $, +Sheet1!$B$3, but it still changes.
You can use the indirect function in excel.
+INDIRECT("Sheet1!B3")
With the caveat that you never change the location of column A you could do the following:
=INDEX(Sheet1!$A:$$ZZ,ROW(B3),2)
Caveat: as set up will only work for cells between and including columns A and ZZ. the ZZ reference will increase as columns get added. If you have columns outside of ZZ initially, then you will have to adjust the final column reference to suit your needs.
INDEX gave me some errors in the function (probably on my end), but I managed to solve it using INDIRECT.
Ty for the feedback, #AlexCollins #ForwardEd

Expanding an Excel formula without referencing the previous cell

I am attempting to use an IF statement to check whether the sum of two cells from another Excel sheet is greater than or equal to 1.
For a sheet called Test1 with the values of interest in column C, this is what I have so far, which works fine:
=IF((Test1!C1+Test1!C2>=1),1,0)
In column B on a second sheet that I'll call Test2, I want to copy this formula down 200,000 rows. However, if the aforementioned formula is in cell B1, for the formula in B2 I would like the formula to read:
=IF((Test1!C3+Test1!C4>=1),1,0)
I want to copy the formula down the column so that the second cell reference in the formula in the first row does not become the first cell reference in the formula in the second row (eg. it would go C1+C2, then C3+C4, C5+C6, etc.).
I have tried manually entering the formula for a few rows, highlighting those, and copying them down but can't get the desired cell reference pattern. If I highlight and drag these first three formulae down another three rows, C4 and C5 are repeated and not in the correct pair.
=IF((Test1!C1+Test1!C2>=1),1,0)
=IF((Test1!C3+Test1!C4>=1),1,0)
=IF((Test1!C5+Test1!C6>=1),1,0)
=IF((Test1!C4+Test1!C5>=1),1,0)
=IF((Test1!C6+Test1!C7>=1),1,0)
=IF((Test1!C8+Test1!C9>=1),1,0)
I have tried using OFFSET() within this formula but couldn't get it to work. I am basically just wanting to add 1 to each of the cell references in the formula, as compared to the previous row (but not to actually add 1 to the value of that cell, as would happen with C1+1 for example).
Any insight would be greatly appreciated!
If you plan on copying this down 200K rows then you will want the absolute simplest formula that accomplishes the stagger. Avoid the volatile OFFSET function or be prepared to spend a lot of time waiting for random calculation cycles to complete. A volatile function will recalculate whenever anything in the workbook changes; not just when something changes that involved the formula in the cell.
=--(SUM(INDEX(Test1!C:C, (ROW(1:1)-1)*2+1), INDEX(Test1!C:C, (ROW(1:1)-1)*2+2))>=1)
The following formula should do the trick:
=(SUM(INDIRECT("C"&ROW()*2-1);INDIRECT("C"&ROW()*2))>=1)*1
And that's the version using IF:
=IF(SUM(INDIRECT("C"&ZEILE()*2-1);INDIRECT("C"&ROW()*2))>=1;1;0)
You say I am basically just wanting to add '1' to each of the cell references in the formula but appear to be incrementing by 2, so I am confused but an option might be to apply you existing formula to 400,000 rows, together with =ISODD(ROW()) in another column, then filter on that other column to select and delete those showing FALSE.
Excel's autofill won't do the 2-cell shift that you're looking for. You can use the functionality that is there.
Put =IF((Test1!C1+Test1!C2>=1),1,0) in the top cell and drag a copy to the second row (it will be =IF((Test1!C2+Test1!C3>=1),1,0) but that's okay). Now, put 'A' and 'B' in the next column. Select all 4 cells and copy them down 400k rows.
Use filter to delete rows flagged with 'B' and delete the blank rows.
(Select blank rows with [F5] click Special and select Blanks, then right-click and delete)
Here is all you need. It's fast and nonvolatile.
=--(SUM(INDEX(Test1!C:C,ROW(1:1)*2-2):INDEX(Test1!C:C,ROW(2:2)*2-2))>=1)
Copy it down as far as you like.

Excel Conditional Formatting Probsss

I am using conditional formatting in Excel to compare two sets of data (set 1 in column A and set 2 in column D). The conditonal formatting is in column F so if column A=D then column F will turn green and if A /= D then column F will turn red.
The problem is when I delete the first cells in A and D and shift all the cells below up, the whole conditional formatting gets erased. Is there a way to keep that conditonal formatting permanent?
[Im having trouble uploading pics for some reason...if I could, I would include a pic so it's easier to understand what's goin on]
This is a general feature of Excel, not just of conditional formatting. In short, Excel tracks each cell as a unique object, and if it gets moved around (like a row is deleted), then it automatically shifts the reference to that object to refer to its new location.
Hypothetical Example
Consider a formula in cell F5, which says '=A5+D5'. If you rightclick on A3, delete that cell and shift cells up, the formula in F5 will now read '=A4+D5', because the old reference to A5 has now shifted upwards by 1.
You can theoretically solve this by using the INDIRECT function. In the example above, let's say you wanted to delete A3, and then you wanted the cell in F5 to still read '=A5+D5', even though the old A5 had shifted up. You could do this with the following formula:
=INDIRECT("A5")+D5
Because you are indirectly referring to A5 by explicitly writing it out as a text string, it won't move around when rows and columns change. Be warned that this is often counter intuitive. If you insert a new row above row 2, for example, your formula would now read:
=INDIRECT("A5")+D6
Note that D6 automatically shifted, but INDIRECT("A5") did not. This is likely not the desired result. However, if we assume that you will often be deleting (and shifting up) cells in column A, but you want all other worksheet changes to be incorporated, we can do what you want. Again ignoring your specific question for now, consider the above example. How can we change it so that when a whole new row is added, the formula ultimately becomes A6+D6? But at the same time, when A3 is deleted, have the formula now read A5+D5? In short, we do this by referencing the row that D5 is on, as follows:
=INDIRECT("A"&ROW(D5))+D5
Now, if a whole row is added, both instances of D5 in the above formula become D6. But if A3 is deleted, the "A" remains "A", and the D5 instances remain D5.
Actual Solution for your case
In your conditional formatting therefore, the formula would be as follows [Applied to all of column F, or however much of column F you want, starting with F1] [two rules one where A<>D and one where A=D; or, make formatting GREEN by default and have RED only apply where A<>D]:
=INDIRECT("A"&ROW(D1))<>D1
The cause of this problem is likely that the cells you deleted were referred to in the conditional formatting syntax. For instance, if you have a conditional formatting, applied to cells F1:F5 with the formula =$A1=$D1, and then delete cells A1:A3 and D1:D3 (shifting cells up), you will notice that the conditional statement is now only applied to cells F3:F5. Excel tries to update these references for you, but occasionally that isn't what is desired.
Using a formula that doesn't directly refer to the cells will fix this. For instance:
=OFFSET($F1,0,-5)=OFFSET($F1,0,-2)
and
=OFFSET($F1,0,-5)<>OFFSET($F1,0,-2)
Now, when you delete any cells in columns A or D, the conditional formatting will still be applied to all rows.

Excel 2010: Counting cells with adjacent cell blank

I have data in rows where each column represents a day, some of which are blank and some of which have numbers. I want to "scan" down the row, comparing each cell with the one before to the left of it (or the one 2 spaces left of it, etc). For example, I want to sum the number of cells (days) with a blank in the cell before it. Or, I want to sum the number of cells that are greater than the cell to the left of it. I can't figure out how to dynamically compare to the prior column using addresses that change with each cell.
This is from what I understood from your Question:
If you refer to the screenshot below, you want to count Columns B to H if the column has a number and the column to the left is blank.
So, if this was just one column, we would write the formula as:
=COUNTIFS(B3,">0",A3,"")
Now since you want to do this for a range of columns (an array of cells), you need to do something like:
=COUNTIFS(B3:H3,">0",A3:G3,"")
and accept with a Ctrl + Shift + Enter.
So the formula would be displayed as:
{=COUNTIFS(B3:H3,">0",A3:G3,"")}
Array formulas are perfect for this task. I can't give you a lecture on the topic but you should read on it. Basically, you can select multiple cells in a range and act as if it was one cell.
For example, you could do something like this:
=SUM(IF($A$1:$A$100="", 1, 0))
When you enter array formulas, be sure to hit CTRL + SHIFT + ENTER in the formula box to signify that you want Excel to treat this formula as an array formula. Otherwise you will not get the expected results.
Using this method you can do any kind of comparison. Sometimes it helps to see how Excel treats the formula. You can select part of the formula in the formula editor and hit F9 to see what this segment computes to according to Excel.

Copy formula across columns

I have a spreadsheet with 4 columns : A, B, C, D.
I want to calculate the difference between A-B and C-D. So in cell E2 I enter the formula =A2-B2 , and get the result that I want, which is the difference between A-B.
Now I drag the formula in E2 to cell F2, expecting that Excel will "think" that now I want the difference between C-D. However, when I drag the formula from column E to column F I get =B2-C2 (you see, Excel assumes I want to use B2 again).
My question is: how can I make Excel “understand” that I want to use =C2-D2 after =A2-B2, and NOT =B2-C2?
This an abbreviated example. The original data-set has hundred of columns. Thanks for your help.
Enter Formula in E2
Drag the formula up till G2. Now G2 will have the formula which you want.
Delete Col F. Now Col G will move to Col F, which will have your required formula
There's no way in the UI that you get Excel to "think" that much - it'll only shift the references by one column if you drag it across. If deleting the columns in between is not an option, you need to rewrite you formula, e.g.:
=OFFSET(A1,0,COLUMN(L1)-COLUMN($L1))-OFFSET(B1,0,COLUMN(L1)-COLUMN($L1))
In this example, it is assumed that you start showing the difference in column L - of course you need to adjust according to your worksheet - but once done, you can drag the formula to the right as far as you need.
As your original data-set has hundreds of columns, you may want to use a non-volatile formula, eg:
=INDEX(A1:K1,1+COLUMN(L1)-COLUMN($L1))-INDEX(A1:K1,2+COLUMN(L1)-COLUMN($L1))
This will speed up calculations in the workbook. Depending on how big the data-set is and how many other formulas are in the workbook, the difference in speed could be enormous.
The same conditions apply as in Peter's example.

Resources