Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

arrayformula that can "skip" rows

I need to introduce functionality into a google spreadsheet that will allow the user to edit the result of an array formula. The reason for the requirement is that an ARRAYFORMULA sets a default value for a group of cells, but the user sometimes needs to overwite these defaults. I'd like to know if this is even remotely possible.

example:

Row(#)|Array_1 |Array_2
------------------------------------
 1    |a       |=arrayformula(Array_1)
 2    |b       |""
 3    |c       |""
 4    |d       |""

So all rows in Array_2 are populated by an array formula. However the user wants to go directly to the second cell in Array_2 and change its value. Of course, by design ARRAYFORMULA will break. Is there some way to modify ARRAYFORMULA, so that it will simply skip over the cell that the user has edited and continue on its way as if nothing has happeded?

like image 372
user27636 Avatar asked Jul 14 '14 20:07

user27636


People also ask

How do I ignore rows in Excel?

Combine the IFERROR, INDEX, SMALL, IF, ROW, & ROWS Functions to Skip Blank Rows. We will make an array formula using the IFERROR, INDEX, SMALL, IF, ROW, and ROWS functions altogether. This array function will skip all the blank rows out of the data table in Excel.

How do you skip an array in Excel?

Entered with Ctrl-Shift-Enter. This does that. It skips row 3.

How do you skip a cell in Google Sheets?

Jump to Cells Using the 'Go To Range' Option. In Google Sheets, there is a way to simply type the cell reference (or the range reference or row/column number) and quickly jump to it. This can be done using the 'Go To Range' feature in Google Sheets.

Does Sumifs work with Arrayformula?

Unlike standard formulas, the function is expandable, so it iterates on new data instantly. You can also use ArrayFormula in conjunction with other functions, such as VLOOKUP, FILTER, IF, or SUMIF.


1 Answers

I realize this is an old problem but I was searching for this today and made a script that works for me.

This script puts a formula in an adjacent cell when a cell is edited in the second column. This way you can just overwrite the formula if you need to input something manually and you don't need to have the formulas go into all of the rows beforehand. I had people accidentally edit the formula and mess it up most of the time when they were pre-filled, so this works better for me.

function onEdit() {

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheetList = ["Sheet1","Sheet2","Sheet3"]; // list of sheets to run script on

    for (i = 0; i < sheetList.length; i++) {

        var sheetName = ss.getSheetByName(sheetList[i]);

        // only runs if sheet from sheetList is found
        if (sheetName != null) {

            var aCell = sheetName.getActiveCell();
            var col = aCell.getColumn();
            var adjacentCell = aCell.offset(0, -1);
            var formula = 'INPUT FORMULA HERE'; // put the formula you want in the adjacentCell here. Don't use it in an arrayformula

            // only runs if active cell is in column 2, if the adjacentCell is empty, and if the active cell is not empty(otherwise it runs if you delete something in column 2)
            if(col==2 && adjacentCell.getValue()=="" && aCell.getValue()!="") {

                adjacentCell1.setValue(formula);
            }
        }
    }
}
like image 102
Eli Madsen Avatar answered Oct 22 '22 17:10

Eli Madsen