I have three columns with information filled in already. The value in Column C is dependent on two identifiers from Columns A & B (i.e., George is always the seller of Apples in America, but Sarah is the seller of Beets).
I have enough data in rows 1-8 that I want the cells from 9 onwards to start automatically filling the required information each time I input a new row.
Thus, if I enter in "Beets" in A9 and "Australia" in B9, then C9 should pull the value "Amy". I will pull this value down to autofill the rest of the table for future rows to be added automatically filling.
I used the INDIRECT(ROW-1) function to reference the whole column above the cell with the formula to get the correct data, if that makes sense…
A B C
1 Product Country Contact
2 Apple Australia John
3 Apple America George
4 Beets Australia Amy
5 Beets America Sarah
6 Carrot Australia Greg
7 Carrot America Belinda
8 Apple Australia John
9 Beets Australia _Formula:_
=INDEX((INDIRECT("C2:C"&ROW()-1)),MATCH(A10,IF((INDIRECT("B2:B"&ROW()-1))=B10,(INDIRECT("A2:A"&ROW()-1)))),0)
Best Answer
Here's an answer that seems to work:
Working from the inside out:
VLOOKUP(B9, OFFSET(B$2:C$7, MATCH(A9,A$2:A$7,0) -1, 0, 2, 2), 2, 0)
MATCH(A9, A$2:A$7, 0)
findsA9
(Beets
) in the rangeA2:A7
{Apple
,Apple
,Beets
,Beets
,Carrot
,Carrot
}, yielding an index value in the range 1-6. Of course, becauseA2
=A3
,A4
=A5
, andA6
=A7
, the index value will always be 1, 3, or 5; forBeets
, it is 3.MATCH(A9, A$2:A$7, 0)-1
remaps the above to be in the range 0-5 (specifically, 0, 2, or 4; forBeets
, it is 2).OFFSET(B$2:C$7, the_above, 0, 2, 2)
saysB2:C7
region,B2
), go down two rows (since the first occurrence ofBeets
inA2:A7
is in the third row, that means we must go down two (3−1) rows from row 2) and go right zero columns, arriving at cellB4
,B4:C5
, which is which is the world-wide list of beets sellers. Note that we want a region that’s two columns wide, because we want to associate countries with sellers, but the height should be the number of countries (which happens to be two in this example). If there were seven countries, we would change this toOFFSET(B$2:C$7, MATCH(A9,A$2:A$7,0)-1, 0, 7, 2)
(Although, if there were seven countries (and three commodities), the introductory block would be 21 rows high, so we’d be using ranges from row 2 to row 22.)
VLOOKUP(B9, OFFSET(B$2:C$7, MATCH(A9,A$2:A$7,0)-1, 0, 2, 2) , 2, 0)
VLOOKUP
(and its brothers,LOOKUP
andHLOOKUP
) are, essentially, shorthand forINDEX
+MATCH
. This searches the first column (theV
stands for vertical) of the beets sellers region/array (B4:C5
) forB9
(Australia
) and then returns the value from the 2nd column of the row that matched the lookup value (Australia
).Australia
is in row 4. Since we are talking about ColumnsB
andC
, ColumnC
is “the 2nd column” in this context, so this gets us to cellC4
, which containsAmy
.… which is the desired result for row 9, since Amy is the Australian beet vendor.