Change value of cell in same row with google script if column has certain value

前端 未结 1 701
迷失自我
迷失自我 2020-12-11 11:50

I am working on a simple tracking tool for products with google Sheets. The top row has components ranging from 1 to 13 for a product. When all the components are checked as

相关标签:
1条回答
  • 2020-12-11 12:11

    The combined use of formula and scripts means it's not as straightforward as it could be. If you were using a script to perform all the changes, you could just add a timestamp when the rest of the script runs.

    As it is, one solution would be to have a script that runs every few minutes to check if column 'R' has the value 'Ready' and column 'S' has no timestamp, and if that's true = Add a current timestamp.

    A simple but inelegant way to do this would be:

    function timestamp(){
    
      var sheet = SpreadsheetApp.getActiveSheet();
      var lastRow = sheet.getLastRow()
    
      for (var i = 1; i <= lastRow; i++){
    
        var readyRange = sheet.getRange([i], 18);
        var readyValues = readyRange.getValues();
    
        var timeRange = sheet.getRange([i], 19);
        var timeValues = timeRange.getValues();
    
        if (readyValues == 'Ready' && timeValues == ''){ // 
          timeRange.setValue(new Date());
    
          }
        }
    }
    

    This will run through all the rows in the spreadsheet and check if they need a timestamp. You can then set a time trigger for this to run every once in a while.

    This works fine for small spreadsheets, but I've thrown it together as a solution in a few minutes, so you'll need to make it more efficient if you intend to use it with several thousand rows.

    0 讨论(0)
提交回复
热议问题