Excel: How to Copy Hlookup position down? - excel

I have an Hlookup formula and was trying to copy it down but the position number doesn't change. I Would like to be able to copy it down to other cells and need the position to change by 1 for each cell.
Hlookup(A1,B1:D20,2,False)
When I copy the formula down , I need 2 to become 3. Any help is appreciated. Thanks!

The easiest why to do that is to have a column with the return position you want. So:
Hlookup(A1,B1:D20,zz1,False)
cell zz1 has: 2
cell zz2 has: 3
etc...
If you don't like that you can add 2 plus row() and maybe subtract to get where you want when you copy.

Perhaps add another column to refer to as this number? Then, have this column increment by one either by formula or using Excel to do it for you. Thus, if your formula was in cell A2:
// in cell
E1: 2
// in cell (and copied down)
E2: =E1+1
Then, in the cell you mentioned, the formula would become something like:
=hlookup(A1,B1:D20,E1,False)

Related

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 - Offset to last non-blank cell

From my research, when a bunch of cells are merged, you can only reference the first row and first column of the merged cells. EG. if A1:A3 are merged, then I can only access the data using A1 only, and A2 and A3 returns 0.
Now let's say I have a column B that has a formula that calculates based on values in column A. If I drag this formula down, then B2 and B3 will end up using value of 0, when they should be using value in A1.
Effectively, what i want to do is "if the cell in column A (of this row) is blank, then use the last non-blank value going upwards".
I know this will need to combine a couple of formulas, but I can't figure out how to create this. For a start, I can use the Offset function to "go up", but the difficult part here is how to find the previous non-blank cell?
I also tried combing OFFSET with COUNTA (see https://www.exceltip.com/other-qa-formulas/get-the-value-of-the-last-non-blank-cell-in-a-column-in-microsoft-excel.html), but this doesn't work if this occurs multiple times.
Easiest way is to use a helper column:
In B2 write
=IF(NOT(ISBLANK(A2)),0,B1+1)
and in C2 write
=OFFSET(A2,-B2,0)
Edit: actually... the solution without helper column is even easier! Write in B2:
=IF(ISBLANK(A2),B1,A2)
To avoid the helper column, you can use the INDEX + AGGREGATE functions:
=INDEX($A$1:A1,AGGREGATE(14,6,($A$1:A1<>"")*ROW($A$1:A1),1))

Offset with sum Excel

I have a workbook with Columns A1:A9 - I1:I9 containing numbers. Column J1-J9 shows the values of A1-I1. What I would like to do is show the sum of A1:A9 in J1 and follow that method down. Here is my offset formula:
=OFFSET($A$1:1,0,ROW(A1)-1,1,1)
Is there a way to add a SUM to this?
Best I can understand, you want to sum A1:A9 in J1 and B1:B9 in J2 and so on...
If that is correct, put this in J1:
=SUM(INDEX($A$1:$I$9,0,ROW(A1)))
and drag down.
Note if there is no data below then one can use:
=SUM(INDEX(A:I,0,ROW(A1)))
Scott is correct, here is another way:
=SUM(INDIRECT(ADDRESS(1,ROW())):INDIRECT(ADDRESS(9,ROW())))
Copy and paste down the column.

Drag formula down and change the reference of the column (index+match)

I need help with the following formula:
=INDEX(Sheet2!A2:A11,MATCH(Sheet1!Q5,Sheet2!C2:C11,0)+0)
(this part needs to change column references: Sheet2!C2:C11,0)+0)
I need to change the column reference whenever I'm dragging it down. I tried this:
=INDEX(Sheet2!$A$2:$A$12,MATCH(Sheet1!Q4,OFFSET(Sheet2!$A$2:$A$12,0,ROW(O$4:O4)-1),0)+0)
but it always comes up with #N/A
I tried solution from other topics but couldn't find one that uses index and match.
PS. My formula starts from cell O5
Can you advise please?
Much obliged
In general, if you want to change the column reference when dragging down, use a combination of INDEX and ROW, e.g.
= INDEX($1:$1,ROW())
This will grab values further to the right in the first row as the formula is dragged down.
You can also modify this to have INDEX return a range (instead of just a single cell) to be used as part of another formula, e.g.
= INDEX($1:$5,0,ROW())
This returns a 5x1 array which shifts over to the right as the formula is dragged down. (The 0 in the above formula indicates to select all of the rows in the $1:$5 range.)
In your formula, you can try replacing this:
Sheet2!C2:C11
With this:
INDEX(Sheet2!$2:$11,0,ROW()+<offset>)
Where <offset> is the necessary offset that you need.
If your formula starts in O5 and you want that first formula to grab the C column, I imagine that <offset> should be -2. This is because ROW() of O5 is 5, but you want that cell to grab the 3rd column (so you need to subtract 2). Then when you drag down to O6, that part of the formula would evaluate to Sheet2!D2:D11, and in cell O7, it would evaluate to Sheet2!E2:E11, etc.
So your final formula should be:
= INDEX(Sheet2!A2:A11,MATCH(Sheet1!Q3,INDEX(Sheet2!$2:$11,0,ROW()-2),0)+0)

Excel Drag to increment sheet name between file

how to drag to increment the excel sheet from different file?
eg,
Cell A1 =+'[filename]59'!J6
Cell B1 =+'[filename]60'!J6
Cell C1 =+'[filename]61'!J6
i tried this now
=INDIRECT("SHEET"&COLUMN()-1&"!J6")
and readjust all the name etc, and now i wanna drag down and increment the cell to J7,J8,J9 etc
how do i do it?
Help please
Try =INDIRECT("SHEET"&COLUMN()-1&"!J"&ROW()). ROW() returns your current row. So, if you write =ROW() in A15, you'll get 15. Good for dragging down :)
If you want to change the value so that it matches a row different from your current row, you'll need to add or subtract from ROW(). So, if you wanted to put this in some cell B2 or C2 and have it match up to J5, you'd have to add 3. That would work like this:
=INDIRECT("SHEET"&COLUMN()-1&"!J"&(ROW()+3))
Obviously, you should change the 3 to whatever adjustment value you need.

Resources