I am trying to find the next matching row in a table (not just a range) that matches the current cell's value. I have tried to pass in the column from the next row to the end of the column but cannot get it to work. All ideas are welcome! E.g.
Current idea that doesnt work: =MATCH([#Value],OFFSET([#Value],1,0):[Value])
Example data:
Row Value Next_Match
1 1 #N/a
2 2 4
3 3 6
4 2 5
5 2 #N/a
6 3 #N/a
Try this
=OFFSET(B3,MATCH(B3,B4:B$100,0),-1)
assuming B100 is the last row and you want to match only afterwards... Otherwise use B2:B100 etc
Oh and data is in Columns A,B,C
Although the perfectionist in me rather's
=IF(ISNA(MATCH(B3,B4:B16,0)),"Last",OFFSET(B3,MATCH(B3,B4:B16,0),-1))
Related
Consider a table like the following:
WEEKNUM HOURS WEEKTOTAL
==============================
1 2
1 4 6
2 3
2 5
2 1 9
3 6 6
... ... ...
I am searching for a formula to use in the WEEKTOTAL column that sums those entries in the HOURS column that share the same weeknumber. I would like the actual subtotal entry to be added in the row that contains the last occurrence of each weeknumber (the entries are likely sorted by weeknumber). The other cells in this column can be empty.
I'm hoping this is possible using an ARRAYFORMULA, but I am not sure how to.
Thank you in advance!
Assuming "WEEKTOTAL" cell is C1.
in C2 :
=IF(A2<>A3,SUM(OFFSET(B2,0,0,-1*COUNTIF(A:A,A2))),"")
and drag downwards.
Idea : use countif() to 'drive' offset() range. Which in turn will be the range for sum(). All only happens if the next column a value is different (IF(A2<>A3, .. ) ).
Pls share if it works/not/understandable.
So here's my problem:
I've got 2 sheets. (A and B).
2 Cells 2 Match (SheetA!A and SheetB!A)
6 Columns to average (B-C-D-E-F-G)
SheetA!A1 and SheetB!A1 If those two match, the average needs to be for cells B1-C1-D1-E1-F1-G1).
I've got a few thousands rows in each sheet. SheetA is the "Data Sheet" where all the data is. And SheetB is like my workbook, where all the stats will be.
I tried this function:
=AverageIf(SheetA!$A:$A;A2;SheetA!B:G)
I also tried
=average(index(SheetA!$B:$G;MATCH($A2;SheetA!$B:$G;0)))
Which doesn't seem to work either. But I know I probably made an error with this formula.
The function only gives me the value in cell B, it doesn't calculate the average for the 6 cells on the same row. Text1 and Text5 are the texts to Match from SheetB in SheetB
##SheetA##
A B C D E F G
Text1 1 2 3 1 2 3
Text2 2 3 1 1 1 1
Text3 1 1 2 1 2 2
Text4 3 5 2 4 5 1
Text5 4 2 2 2 2 2
##SheetB##
What I would like on SheetB:
A B
Text1 2
Text5 2.33
The formula I showed Previously gets me the following, it doesn't calculate the average, only gets me the first value:
A B
Text1 1
Text5 4
It matches the right row with Text1 from SheetA and SheetB.
Ok, this will work if you have the data as I show. If not, you need to adapt the MATCH part to make sure the formula will work.
Data in SheetA is like this, starting at row 1 (this is important):
My formula is in SheetB in column B, and is like this:
=AVERAGE(INDIRECT("SheetA!B"&MATCH(A1;SheetA!A:A;0)&":G"&MATCH(A1;SheetA!A:A;0)))
And I get this:
How this works:
MATCH will get the row number of the range you want to average (if found, ofc). Because my data starts at row 1, the number returned by MATCH is good. If your data does not start at row 1, you need to adjust it (+1,+2, whatever you need).
INDIRECT will return the range in same row, but between columns B and G from SheetA
Finally, AVERAGE will make the average.
There is no error handling if something is not found, but if you need it, just add something like IFERROR.
Also, MATCH will only work if the match is 100% exact. In your example in SheetA you have Text1 but in SheetB you typed Text 1, which are not equal. Make sure you type them right.
Hope you can adap this to your needs.
Current Next 1 Apple
2 5 2 Boy
3 Cat
4 Apple
5 Boy
6 Cat
7 Apple
I have cell 1 that contains the value "2". I need a formula that would return the next value in a column that contains the value "oy" in another column. But it cant return the same value, has to return a value greater than the current. So next value greater than 2 that contains "OY" in another column.
Example should return the number 5.
Can anyone help?
Use INDEX/MATCH to set the RANGE and another INDEX/MATCH to return the value:
=INDEX(INDEX(C:C,MATCH(A2,C:C,0)+1):C1040000,MATCH("*oy*",INDEX(D:D,MATCH(A2,C:C,0)+1):D1040000,0))
Avoid using OFFSET or INDIRECT as they are volatile functions.
I have two columns of data, they look something like this:
A B C D
1 2 SOME RECORD
2 6 SOME RECORD
3 10 SOME RECORD
4
5
6
7
8
9
10
So basically column A is a list of indices, where some of them appear in column C with corresponding records saved in column D. Column B is currently empty, and what I want to do is if say index 2 appears in both column A and column C (they matches), then put the record beside C2 in the cell B2. So essentially I want it to look like this:
A B C D
1 2 SOME RECORD
2 SOME RECORD 6 SOME RECORD
3 10 SOME RECORD
4
5
6 SOME RECORD
7
8
9
10 SOME RECORD
Can someone help please?!! Thanks!!!
UPDATE: I tried this and it doesn't work. The data in column D is calculated using a UDF and is refreshing every 1 second. The VLOOKUP function fails even though I can see the 2 indices are the same!! Is it because of the format of the cell or column? I.e. does vlookup compare data type as well?
Assuming your data in A starts from A1 - put in B1 the following and autofill:
=IFERROR(VLOOKUP($A1,$C:$D,2,0),"")
This includes handling of missing values.
You'll want this:
B1=VLOOKUP(A1, C:D, 2, FALSE)
This will look up the value in column A within the array spanning columns C and D. It will give you the value found in the second column (D). FALSE makes it an exact match, otherwise you might get 2 and 20 matching because hey, they're kind of similar...
Using vlookup, when a match occurs, I want to display the value of column C from sheet 2 from the same row where the match occurred. The formula I came up with takes the value from column C sheet 2 but it takes it from the row where the formula is pasted on sheet 3 instead of where the match occurred.
Here's my formula that doesn't work:
=IF(VLOOKUP(Sheet1!A:A,Sheet2!A:A,1,FALSE),Sheet2!C:C,"NODATA")
How can I take the value from the row where the match occurred?
To be clear, I am not entirely certain I understand what you are trying to achieve. Maybe the following helps...
Suppose I have 3 sheets in a workbook as follows:
Sheet1 Sheet2 Sheet3
A A B C A B
1 10 2 h Apple 10 Apple
2 20 g 4 Banana 25 n/a
3 30 l ! Pear 40 Grape
4 40 g * Grape 30 Pear
In column B of Sheet 3 I have the following formula:
=INDEX(Sheet2!$C$1:$C$4,MATCH(VLOOKUP(A1,Sheet1!$A$1:$A$4,1,FALSE),Sheet1!$A$1:$A$4,1))
To explain:
The VLOOKUP looks up the value from Sheet 3, Col A in Sheet1
The MATCH returns the row in Sheet1 of the VLOOKUP result
The INDEX then uses the row number to pick the right value from the value in Sheet2
Again, not sure if this is what you wanted exactly. It may help you get you started...
You need to manually get the index you're looking for, then get the value at that index:
=INDEX(Sheet2!C:C, MATCH(Sheet1!A:A,Sheet2!A:A,FALSE))