I have a helper column with the following code
=IF(A1<>A2,1-SUM(B1),SUM(B1))
The table looks like
When I delete a row, say row 21 in this example, I end up with a ref issue in cell B21 -
=IF(#REF!<>A21,1-SUM(#REF!),SUM(#REF!))
Is there any way to resolve this, perhaps with a way to sequence the formula in cell B2 such that it automatically runs the calculation and corrects based on rows being removed?
You can use the offset function to avoid this and always make the formula look to the above cell like this:
=IF(OFFSET(A2,-1,0)<>A2,1-SUM(OFFSET(B2,-1,0)),SUM(OFFSET(B2,-1,0)))
This tells to use A2 but 1 row less, making it A1. (And same for B2.)
In B2 use: =IF(INDEX(A:A,ROW()-1)<>INDEX(A:A,ROW()),1-SUM(INDEX(B:B,ROW()-1)),SUM(INDEX(B:B,ROW()-1)))
By using INDEX you can avoid referencing cells that may be deleted, which is causing the issue you have.
Related
I'm working on a workbook that will have a master list of tasks for a group, and then each person within that group would have a worksheet with their specific information. I'd like to make a few columns of information from those sub-worksheets populate back into the master list.
I think what I want to do is an indirect reference to the worksheet tab names. The following formula works for me:
(B2 in this is a column that references the worksheet name, and E2 is the cell from that worksheet that i want returned)
=INDIRECT(B2&"!E2")
so, for example, B2 might say "Sarah", in which case the formula returns the value from cell E2 on worksheet "Sarah", which is exactly what I'm wanting to happen.
The problem I'm running into is that when I drag this formula down to the next row, my cell reference to E2 stays the same rather than progressing to E3 like I would like it to.
I have 3000 rows that I'd like to do this for, so manually re-typing the row # isn't sounding like fun. Is there any way to make that automatically progress?
I'm pretty sure my issues are in those " marks, but I'm drawing a blank. Can anyone help?
I did some more digging, and came up with the following solution:
=INDIRECT($B2&"!"&CELL("address",E2))
it seems to work. It might not be the most elegant of solutions, but I'll take it!
Consider something like:
=INDIRECT($B$2 & "!E" & ROWS($1:2))
We want to "freeze" he B2 and propagate the cell reference.
Maybe it didn't work because the sheet name contains one or more spatials. This would then work with: =INDIRECT("'"&B2&"'!E2")
It's probably a simple problem, but I did not even know the keywords to google it ;/. Let's say I have this data :
Now I also have this litle formula:
If I know drag the C cell to the right, Excel will attempt the following caluclation:
=2+B1
What I want him to do is to attempt this calculation
=2+A2
Of course the easiest solution would be to store my initial data in one row instead of 1 column, but it is really inconvenient for me. Thanks for any help
You can use the indirect() method to reference a cell by it's "String identifier", i.e. "A3". When filling out to the right, use CONCATENATE() and COLUMN() to create your String identifiers {A1,A2,A3,A4,A5...} as required:
=2+INDIRECT(CONCATENATE("A";COLUMN()-2))
This will result in the following:
Side-Node: If you want this for some x/y-Grid-Generation, you can also be lazy,
and just insert =COLUMN() for every cell from "A1 - Z1" and ROW() for every cell from "A2 - A24".
(Or even avoid these at all and directly perform your actual calculation by using column() and row() as replacement for your x/y.
You may try using a combination of the INDIRECT and COLUMN functions:
=2+INDIRECT("A"&(COLUMN()-2))
You would paste the above formula into cell C1, and then drag across to the right however many columns/rows you wanted to cover.
This would result in the following:
This works because COLUMN()-2 returns 1 for the C column, 2 for the D column, and so on. Therefore, the formula will be calling INDIRECT on A1, A2, etc. for column C, D, and so on.
In general, if you want relative references to move down as cells are dragged to the right, you can use this:
Instead of:
= 2+A1
Do:
= 2+INDEX($A:$A,COLUMN()+<offset>)
Where <offset> is whatever offset you need. The offset will change depending on which column the starting formula is located in.
INDEX should be preferred over INDIRECT because INDIRECT is volatile (must recalculate after any change to the workbook) but INDEX is not (only recalculated when one of the inputs the formula, in this case $A:$A, changes).
In the screenshot provided, I am trying to extract all of the flow data into one column by itself. I got started using the INDEX function, but I believe I am missing something. In the screenshot, cell G2 should contain the value "998", which it does. Starting from cell C8, flow values occur every 14 rows in that column, so I want to write a function that when I copy and paste starts looking at cell C8 and returns the value every 14 rows. What I have so far is this:
=INDEX(C8:C354528, ROW(C1)+14)
This is close, because it does return me the value "998", but going forward, it basically moves my array selection down by one and the counts 14 rows...not what I want.
As an example, the next two values after "1000" should be, 998 and 992.
What am I missing here?
If you can use a second helper column, you can use this Array formula to find such rows. Note that this has a benefit in that your rows can be in any order - you aren't relying on the fact that "Flow" data is exactly X rows apart.
In Column I, let's say, in I1, you can put this:
=IFERROR(SEARCH(" Flow ",$B1),"").
Then, where you want to keep your Flow numbers, you can use this array formula:
=INDEX($C$1:$C$100,SMALL(IF($I$1:$I$100<>"",ROW($C$1:$C$100)-ROW($C$1)+1),ROWS($C$1:C1)))
(enter using CTRL+SHIFT+ENTER)
Use this:
=INDEX(C:C,8+(ROW(1:1)-1)*14)
And copy/drag down.
As stated in the comments OFFSET is volatile and should be avoided when possible. INDEX() is not volatile.
I am using a formula in Excel 2010 to display the individual with the most wins, as below:
IF($P$3="Most wins",SUM(LARGE(Wins,{1})),"FALSE")
where wins represents an array of an indefinite number of individuals.
However I would like to be able to autofill this, or similar, such that the next row displays the following:
IF($P$3="Most wins",SUM(LARGE(Wins,{2})),"FALSE")
Unfortunately I can't get the value inside the curly brackets to increment, which is causing no end off issues when the formula is going to be dragged down beyond 1,000 rows.
Is this possible, or am I using the wrong method?
=IF($P$3="Most wins",SUM(LARGE(Wins,ROW(A1))),"FALSE")
Place that in the top of your column and copy it down. As you do, the cell reference for A1 will change from A1 to A2 to A3, etc. The ROW function returns the number of the row of the cell reference.
Alternatively as pointed out in Darren's comment, you could also use ROW()-2 if you data is starting in the second row. This has the advantage if you ver deleted the 1 row or column, you will not screw up your cell references.
I am setting up a vlookup to pull product prices from another sheet within the workbook. The code works for the cell but when i try to expand or copy and past the code into the next row it automatically changes the data table_array value.
=VLOOKUP(B5,Prices!1:65536,3)
Within the code i want the first value, B5 to scale with the row it is in, however the second value needs to remain the same. How do i go about doing this? Also is there a way that i can get the cell to remain blank instead of displaying N/A if there isnt a valid part number?
Thanks for your help!
=VLOOKUP(B5,Prices!$1:$65536,3)
The $ lock the range.
For example.
$A1 will lock the column to A when the formulas is copied other
locations.
A$1 will lock the row
$A$1 will lock both the column and the row.
I can't comment because I do not have enough rep but this will fix user3716271 's formula:
=IF(ISERROR(VLOOKUP(B5,Prices!$1:$65536,3)),"", VLOOKUP(B5,Prices!$1:$65536,3))
The following formula should solve both problems as well, a little more compact and would use one less VLOOKUP():
=IFERROR(VLOOKUP(B5,Prices!$1:$65536,3), "")
As guitarthrower had said, the $ before the number is used to lock the range.
For the second part, an IF formula will work fine:
=IF(ISERROR(VLOOKUP(B5,Prices!1:65536,3)),"",VLOOKUP(B5,Prices!1:65536,3)),"")
And if I understand correctly the first part have you tried set an absolute value? Something like:
=IF(ISERROR(VLOOKUP(B$5,Prices!1:65536,3)),"",VLOOKUP(B5,Prices!1:65536,3)),"")