I'm trying to make several buttons using this script I found. Since I want several buttons with output in different cells I tried adding a variable, which I could set when adding the function to a drawing. This however doesn't seem to work and I have no idea how to do it. So, the button works if I set a cell like "B2" in var activeRange = ss.getRange(DesiredCell); but when I try to use the variables I get "Script function incrementCellValuesByOne() could not be found"
The script I'm using
function incrementCellValuesByOne(DesiredCell) {
// Increments the values in all the cells in the active range (i.e., selected cells).
// Numbers increase by one, text strings get a "1" appended.
// Cells that contain a formula are ignored.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeRange = ss.getRange(DesiredCell);
var cell, cellValue, cellFormula;
// iterate through all cells in the active range
for (var cellRow = 1; cellRow <= activeRange.getHeight(); cellRow++) {
for (var cellColumn = 1; cellColumn <= activeRange.getWidth(); cellColumn++) {
cell = activeRange.getCell(cellRow, cellColumn);
cellFormula = cell.getFormula();
// if not a formula, increment numbers by one, or add "1" to text strings
// if the leftmost character is "=", it contains a formula and is ignored
// otherwise, the cell contains a constant and is safe to increment
// does not work correctly with cells that start with '=
if (cellFormula[0] != "=") {
cellValue = cell.getValue();
cell.setValue(cellValue + 1);
}
}
}
}
Am I doing this completely wrong?