问题
I'm trying to create a search page in google sheets where the user enters a value in one cell(s) and then other cells auto-populate with values from another tab/sheet based on the value entered in the search cell(s).
I'm trying to use VLOOKUP
up in an array but it gives either error or N/A
.
I have 'sheet1' with data from a google forms (columns from A to BN) and I'm trying to make a search page in 'Sheet2' where on top the user can write for example the ID-number, and I want to grab the value of a column from 'sheet1' that matches the ID-number written on the same row for 'sheet1'.
I've already checked:
VLOOKUP to the left from another sheet in Google Sheets
How to get value depending on list selection in spreadsheet?
Google sheets - VLOOKUP inside ARRAYFORMULA
There are others but I'm not looking for any scripts.
In simple form the formula would be:
=VLOOKUP(B3,'sheet1'!A:BN,40,False)
But because I have too many columns and I'll be needing to grab other values too I'm using:
=ArrayFormula(IF(LEN(B3),VLOOKUP(B3,{'sheet1'!A:BN},{iferror(match("ID-number",'sheet1'!A1:BN1,0),"No match")},FALSE),""))
Explanation:
B3 is the cell where the user inputs the id number value
Then ...:
{'sheet1'!A:BN},{iferror(match("ID-number",'sheet1'!A1:BN1,0),"No match")}
is where I'm looking for the number of the column of the title of value I'm looking for, in this case, it is AN, which would be the column 40 but it could be any other.
And then the ArrayFormula is because sheet1 is data from a Google form that is on use and increasing rows constantly.
It gives me an error of #N/A
because it doesn't find the value (input in B3 in sheet 2) in the range (tab sheet1 in all the columns from A to BN that have values)
Example sheet with working answer is [here]: (https://docs.google.com/spreadsheets/d/1qLcJdCn4EdV7lPOAfZ_CMak1LBkve45FL5SXyqBV3L8/edit?usp=sharing)
NOTE: The values to search/return are on the same row in sheet 1 and when a new search is entered then only the row changes.
回答1:
=ARRAYFORMULA(
IF(B3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(B3, data!A:E, {1,2,3,5}, 0)), CHAR(10))), "♦", ),
IF(C3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(C3, {data!C:C, data!A:E}, {2,3,4,6}, 0)), CHAR(10))), "♦", ),
IF(D3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(D3, {data!E:E, data!A:E}, {2,3,4,6}, 0)), CHAR(10))), "♦", ), ))))
UPDATE:
=IFERROR(ARRAYFORMULA(
IF(B3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(B3, {data!AN:AN, data!A:BN}, {41,38,19,11,55}, 0)), CHAR(10))), "♦", ),
IF(C3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(C3, {data!AK:AK, data!A:BN}, {41,38,19,11,55}, 0)), CHAR(10))), "♦", ),
IF(E3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(E3, {data!BJ:BJ, data!A:BN}, {41,38,19,11,55}, 0)), CHAR(10))), "♦", ),
IF(D3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(D3, {data!R:R, data!A:BN}, {41,38,19,11,55}, 0)), CHAR(10))), "♦", ), ))))), "no match found")
回答2:
You cannot use match inside arrayformula. I suggst you to use something like
=ArrayFormula(IF(LEN(B3),VLOOKUP(B3,{'sheet1'!AN:AN,'sheet1'!A:BN},column('sheet1'!X:X)-column('sheet1'!A:A)+1,FALSE),""))
where X is the resulting column (change that to your needs).
来源:https://stackoverflow.com/questions/56331808/search-a-value-from-another-tab-sheet-in-google-sheets-based-on-cell-reference