0

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?

1 Answer 1

1

You can't set a function with a variable to a drawing. You can only set a function.

2 solutions : - You create how many functions for each drawings you have - You create a list in a cell with the name of the cell you want to pass as parameter. And at the begining of the script you check the value in this cell to get the cell value.

var DesiredCell = ss.getActiveSheet().getRange("C1").getValue(); //I imagine the list of cell is in C1, to customize.

So for using the script first you select in drop down list the cell value and after you click on drawing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.