S
S
Shushei1792020-05-13 03:33:00
Google Sheets
Shushei179, 2020-05-13 03:33:00

How to make a script that checks the conditions and runs the corresponding functions?

You need to make a button that will check, for example, if the value in the cell is> 0.1, then a specific function will be performed.
There are 50 lines in total, each line has its own function that simply transfers data from this line to the table, there can be several matches to the condition, and for each condition fulfilled, you need to run the corresponding line function.

It looks something like this:

function getLastRow(sheet, rangeString) {
  var rng = sheet.getRange(rangeString).getValues();
  var lrIndex;
  for (var i = rng.length - 1; i >= 0; i--) {
    lrIndex = i;

    if (
      !rng[i].every(function(c) {
        return c == '';
      })
    ) {
      break;
    }
  }
  return lrIndex + 1;
}

function Func1() {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var lr = getLastRow(ss, 'K1:N155');
  var values = ss.getRange(5, 6, 1, 4).getValues();
  var values = ss.getRange(lr + 1, 11, 1, 4).setValues(values);
  var clear = ss
    .getRange(5, 6, 1, 4)
    .clear({ fomartOnly: true, contentsOnly: true });
}


and plus 40 more of the same functions for each line, now it's just a separate button for each line, that is, you need to click each one to run the script.

and plus 40 more of the same functions for each line, now it's just a separate button for each line, that is, you need to click each one to run the script.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question