问题
Based on (Search a value from another tab/sheet in google sheets based on cell reference), I have 2 tabs/sheets in Google Sheets, one that gathers data from a Google Forms and the other is a Search sheet. The example is here (It's the same one used for the question mentioned above but with added data): (https://docs.google.com/spreadsheets/d/1qLcJdCn4EdV7lPOAfZ_CMak1LBkve45FL5SXyqBV3L8/edit#gid=354631176)
On the top of the Search sheet, I have search fields that the user fills and down in another cell I have a search formula that returns a transposed list of the values found on the same row from Sheet1 matching the value found in Sheet2. But when it encounters a blank cell in sheet 1, it either stops looking for values or gives the value of the next non-blank cell regardless of the indicated rows to return.
Explanation:
On the top of the Search sheet I have search fields in cells B3:F3 that the user fills (row 3) and down in cell B8 I have my search formula:
=ARRAYFORMULA(
IF(B3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(B3, {'Respuestas de formulario 2'!AN:AN, 'Respuestas de formulario 2'!A:BN},
{24,3,21,23,13,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0)), CHAR(10))), "♦", ),
IF(C3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(C3, {'Respuestas de formulario 2'!AK:AK, 'Respuestas de formulario 2'!A:BN},
{24,3,21,23,14,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0)), CHAR(10))), "♦", ),
IF(D3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(D3, {'Respuestas de formulario 2'!AR:AR, 'Respuestas de formulario 2'!A:BN},
{24,3,20,23,13,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0)), CHAR(10))), "♦", ),
IF(E3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(E3, {'Respuestas de formulario 2'!W:W, 'Respuestas de formulario 2'!A:BN},
{24,3,21,23,13,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0)), CHAR(10))), "♦", ),
IF(F3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(F3, {'Respuestas de formulario 2'!Z:Z, 'Respuestas de formulario 2'!A:BN},
{24,3,21,23,13,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0)), CHAR(10))), "♦", ), ))))))
The formula searches for the values entered in B3 to F3 (in Sheet 2) to match them against the data on Sheet 1 (called 'Respuestas de formulario 2') and then returns a vertical list of the values found in that row, skipping one cell after each result, in a certain order (that's why the numbers in between the {} are not in order).
However, Not all cells in Sheet 1 may contain data (For example, if the Google Forms has a skipped section Like those 'If 'yes', go to section 2; if 'no' go to section 3'). The problem is that when the formula encounters a blank cell it seems it either stops looking for the other results or jumps values and returns things from the new cell that has values.
I tried ending it with this but it didn't work:
...{24,34,3,21,23,13,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0)), CHAR(10))), "♦", ), ))))), "no match found")
Then I tried adding the "no match found" in each IF like this but didn't work either:
IF(B3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(B3, {'Respuestas de formulario 2'!AN:AN, 'Respuestas de formulario 2'!A:BN},
{24,3,21,23,13,5,6,9,10,67,53,54,55,56,57,58,59,30,61,27,62,63,64,65,41,38,36,37,31,32,33,34,45}, 0,"no match found")), CHAR(10))), "♦", ),
I'm looking to present a "no match found" in each cell of the results column that is blank while the found values are those corresponding to the listed rows in the {}
in exactly that order.
回答1:
This is a roundabout solution to the problem rather than a fix to the code.
What I did was to create a pivot sheet that pulls the data from the sheet1 (The one with the Google Forms responses) and that fills out all blank cells with N/A . I did this by using the following formula in B1 and dragging it all the way to cell BN1 in the new sheet called 'Pivot_sheet':
=arrayformula(IF(LEN('Respuestas de formulario 2'!$A:$A), IF('Respuestas de formulario 2'!B:B<>"",'Respuestas de formulario 2'!B:B,"N/A"),""))
NOTE: In cell A1 to have the timestamp as reference for answers I merely used:
=ArrayFormula('Sheet1'!A:A)
Then I replaced the reference in the code for the search formula from 'Respuestas de formulario 2'!
to the name of the new sheet 'Pivot_sheet'. Like this:
... IF(B3<>"", SUBSTITUTE(TRANSPOSE(SPLIT(TEXTJOIN(CHAR(10)&"♦"&CHAR(10)&"♦", 1,
VLOOKUP(B3, {'Pivot_sheet'!AN:AN, 'Pivot_sheet'!A:BN}, ...
来源:https://stackoverflow.com/questions/56431884/no-match-message-in-google-sheets-vlookup-results-for-cells-with-no-data