I have a Google spreadsheet with basically a dictionary of key/value pairs. Keys are unique. In a second sheet I need to add one or more rows for every key in the dictionary with some data. In this very sheet I'd need to also report the proper value for each key.
To do so I have tried to combine the ARRAYFORMULA function with a number of other functions on the very first row of the second sheet to avoid (if possible) the need to copy the same formula on all rows of the value column.
So far, neither QUERY nor FILTER worked.
QUERY requires all data, there included the arguments to the WHERE predicate, to reside on a single sheet. In my case, the filtering key would be on the second sheet while the dictionary is on the first one. So this cannot be used at all.
FILTER seems to have a weird (to me) behavior when both used in conjunction with ARRAYFORMULA and without it.
You can have a look to my test Google Sheet here or to snapshots here with ARRAYFORMULA (column B), without it (column C) and what I'd like to get (column D):
A little step further from pnuts' solution provides the "perfect" result without the "N/A" cells:
=ARRAYFORMULA(IF(A3:A="";"";VLOOKUP(A3:A;KEYS!A1:B;2;FALSE)))
Of course there is a major impact on the performances as the VLOOKUP is run once for every single line in in the second sheet (and this was also why I was trying to use FILTER). Those performances are quite low even with the currently linked example sheet, which is really skinny.
Pressing Ctrl+Shift+Enter while editing a formula will automatically add ARRAYFORMULA( to the beginning of the formula.
Inside Filter, there is no need to use the ArrayFormula function. You may have noticed the formula in cell E2. As you can see, the formula returns an array result. In the Filter function in Google Sheets, the column that contains the condition can also be outside the filter range.
To use it in Google Sheets, you can either directly type “ARRAYFORMULA” or hit a Ctrl+Shift+Enter shortcut (Cmd + Shift + Enter on a Mac), while your cursor is in the formula bar to make a formula an array formula (Google Sheets will automatically add ARRAYFORMULA to the start of the formula).
In Row3 please try:
=ArrayFormula(vlookup(A3:A;KEYS!A$1:B$5;2;0))
you can use a From spreadsheet - On change
event trigger to call code like below:
function CopyPasteWastageRows() {
var spreadsheet = SpreadsheetApp.getActive().getSheetByName("<<Sheet-Name>>");
spreadsheet.getRange('Q2').activate();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
spreadsheet.getRange('Q2').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getRange('Q2').activate();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With