Excel: count values on another sheet with dynamic column reference - excel-formula

I have a simple formula in cell B7 of a sheet called Summary Stats that references a sheet called Rolling Returns Data:
=COUNT('Rolling Returns Data'!C$11:C$17202)
I want to be able to dynamically reference the column in the formula i.e. I have letter C in cell B1 of the Summary Stats sheet and want to be able to replace the reference to column C in the formula with a reference to cell B1, so that if I then change the formula that calc. that is then being performed is:
=COUNT('Rolling Returns Data'!D$11:D$17202)

As Scott Craner suggested, use INDIRECT.
=COUNT(INDIRECT("'Rolling Returns Data'!"&A1&"$11:"&A1&"$17202"))
Now you just have to put the letter of the column you want to reference. You can of course change the A1 reference to anything you'd like. Or you can change the code to the following
=COUNT(INDIRECT("'Rolling Returns Data'!"&A1))
and use A1 to specify the address of your column, in this case "C$11:C$17202".

If you're ok using column numbers rather than column letters then this non-volatile formula will work:
=COUNT(INDEX('Rolling Returns Data'!1:17202,11,$B$1):INDEX('Rolling Returns Data'!1:17202,17202,$B$1))
If you really want to use column letters then you can turn a column letter into a column number using:
=COLUMN(INDIRECT($B$1 & 1))
But then you lose the non-volatile nature.
Edit:
If you use the column numbers and leave B1 blank it will return the count of all columns.

Related

Referencing parameter lookup_array in function match in excel

I want to use the match function in Excel the following way: match(True, D2:J2>=K1,0), to find the smallest value that is greater than or equal to lookup_value. My problem is how to change the row number in the array, since the row number is on his part the result of a match function.
Thanks for the help in advance!
Your baseline formula is:
=MATCH(TRUE,D2:K2>=K1,0)
which looks at row #2:
To change that row, lets put 7 in cell A1 to mean use row #7. We change the formula to:
=MATCH(TRUE,INDEX(D:D,A1):INDEX(K:K,A1)>=K1,0)
So the value in A1 defines the row that MATCH() should use.
EDIT#1:
Here is another example of using INDEX() to return a cell reference.
Say we have data in column A. We want the user to be able to select parts of the column (start and stop rows) and sum the part. However, we don't want the user to tinker with the formula. In fact we are going to lock the formula cell so the user can't destroy the formula. We tell the user to put the start row in D1 and the end row in D2.
We put the formula in cell D3:
=SUM(INDEX(A:A,D1):INDEX(A:A,D2))

Find the Last Cell Value of the 2nd Column Set for each 1st Column Cell in EXCEL

I have the following structured table in excel where 1000s of rows included.
I want to return the Last Cell Value of Column B for Each value in Column A.
For example:
For Cell A1 -> I want to return the Cell B5.
For Cell A6 -> I want to return the Cell B9.
I have tried with VLOOKUP, HLOOKUP, INDEX likewise so many formulas where I ended with more conflict situations. Can anyone please write down a Formula to give my requirement a life?
Array formula (Press Control + Shift + Enter while entering the formula) in cell C1 and copy it down.
=IF(A1="","",IFERROR(INDEX($A2:$B$20,MATCH(FALSE,ISBLANK($A2:$A$20),0)-1,2),LOOKUP(2,1/(B2:$B$20),B2:$B$20)))
if you don't mind using column C as a helper column you could use something like that:
If you won't use Array formula you can Use this solution:
like this image:
use column C as helper with this formula in first cell =OFFSET(A1;SUMPRODUCT(MAX(($A$1:$A1<>"")*(ROW($A$1:$A1))))-ROW(A1);0)
and use this formula in column D's first cell =IF(A1="";"";INDEX($B$1:$B$13;SUMPRODUCT(MAX((ROW($A$1:$A$13))*($C$1:$C$13=A1)))))
and copy fill-down to all cells.
Try this shorter, without helper column and non-array formula solution
In C1, formula copied down :
=IF(A1="","",INDEX(B1:B$9,MATCH(1,FREQUENCY(1,0+(A2:A$9<>"")),0)))

Excel string to criteria

I have an Excel formula like this:
=SUM(SUMIF(A2:A11;{"1010";"1020"};B2:B11))
Now I need to make the formula more dynamic. Instead of changing the formula itself, I should be able to change some cell (linked in the formula). This change will be reflected in the formula.
Ex:
=SUM(SUMIF(A2:A11;D2;B2:B11))
Cell D2 should return something similar to {"1010";"1020"} in the first formula.
I tried this and it works only if in the column D I have one value (ex: 1020), but if there are two values (ex: 1010;1020) it returns 0.
This is how my table looks like:
As you can see, it shows 0 for the cell where D2 has two values; but it works when there is only one value. All the rows in column D will be like cell D2, with 2 or more values, this is why it has to be dynamic using a list in the formula.
How can this be achieved in Excel? How can I make a list from the cell?
Using multiple cells would be easier! If the formula cell is one to the right of the criteria cell, you can define a named formula (Using Name Manager) called, say, GetList, which refers to this formula:
=EVALUATE("{"&INDIRECT("RC[-1]";0)&"}")
Then your formula becomes:
=SUMPRODUCT(SUMIF(A2:A11;GetList;B2:B11))

populate Excel Formulas in the an entire column after changing some of the formula values

I have two excel sheets. The one that contains the data "gdsc_en_input_w2" and the other one will contain a selective number of cells from "gdsc_en_input_w2".
I am using the current formula:
=INDEX(gdsc_en_input_w2!$A$1:$YE$13848,MATCH("AKT2",gdsc_en_input_w2!$A$1:$A$13848,0),MATCH($A$3,gdsc_en_input_w2!$A$1:$YE$1,0))
I want to fill an entire column in the second sheet by referencing columns in the "gdsc_en_input_w2" sheet but based on the values stored in the column $A$1:$A$13848. As you can see the second match() matches only $A$3 ...is there a way to fill the required column with the formula with incremental column reference in the second match() function in the formula above. in other words I want to fill in the second cell of the target column the following formula :
=INDEX(gdsc_en_input_w2!$A$1:$YE$13848,MATCH("AKT2",gdsc_en_input_w2!$A$1:$A$13848,0),MATCH($A$4,gdsc_en_input_w2!$A$1:$YE$1,0))
note that the match now has $A$4 instead of $A$3.
Assuming that I am understanding what you are wanting, this formula is going to be in one column where each subsequent row will have a higher number (3,4,5,...) If that is the case, unlock your formula to read:
=INDEX(gdsc_en_input_w2!$A$1:$YE$13848,MATCH("AKT2",gdsc_en_input_w2!$A$1:$A$13848,0),MATCH($A3,gdsc_en_input_w2!$A$1:$YE$1,0)) (I removed the $ in-front of the 3)
Paste that into the whatever your starting cell is, then auto-fill

EXCEL: Need to find a value in a range of cells from another worksheet and return value from adjacent cell

I am trying to find the formula that will search in column A (of worksheet "ABC") to find a value matching G4 in worksheet "XYZ" Once that value is found, return the value of the cell adjacent (column B of "ABC") to the cell in which this formula exists in worksheet "XYZ". All sheets are in the same workbook.
Thank you so much!
here's an example of what you're describing:
In spreadsheet ABC, you have a reference value in column A and data in column B
In spreadsheet XYZ, you have a matching number in column A. You'd like to pair the data from spreadsheet ABC to the value in XYZ:
If you notice the formula in the formula bar on the second picture, you'll see the vlookup formula to pull the data for this example. I also added an apostrophe in front of the formula in cell B1 (image 2) to have it display the formula. Note the formulas are slightly different since they point to different reference cells.
Also, here's a great reference for how the vlookup function works:
http://chandoo.org/wp/2012/03/30/comprehensive-guide-excel-vlookup/
Here is another solution that's closer to your adjusted question.
This solution still uses the vlookup formula. Instead of using it to associate a value on multiple rows, you can look-up a single value. (same function, different application)
Again, I'll point you to a great reference for how the vlookup function works:
http://chandoo.org/wp/2012/03/30/comprehensive-guide-excel-vlookup/

Resources