0

I have created a table in my google sheet, where days refers to columns and rows refers to trials.

Day 1 = [O, O, X, X]
Day 2 = [O, O, X, X]

However, I want to replace all "O" with some value. These values differ per day.
Example: numVal1 = 88 and numVal2 = 99.
For day 1, all O must be replaced with 88.
For day 2, all O must be replaced with 99.

The output must be something like this:
Day 1 = [88, 88, X, X]
Day 2 = [99, 99, X, X]

I'm using a for loop to do this but it's taking too long to finish if I'm working on too many data.
My code is:

 for (var i = 1; i <= data.length + 1; ++i){
    for (var j = 1; j <= data[0].length + 1; ++j){
      var item = ws.getRange(i,j).getValue();
      if(item !== "X"){
        let numVal = ws.getRange(6, j).getValue();
        ws.getRange(i,j).setValue(numVal);
      }
    }
  }
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Welcome to [so]. Please add a brief description of your search/research efforts as is suggested in [ask]. – Rubén Aug 27 '20 at 14:48
  • @berg See the linked duplicate question's(at the top of this page) answers (especially KyleMit's). See [tag info page](https://stackoverflow.com/tags/google-apps-script/info) for **best practices** – TheMaster Aug 27 '20 at 15:13
  • Rolled back as the question is about apps script. Slow execution of loop is due to apps script inbuilt library methods – TheMaster Aug 27 '20 at 16:46

0 Answers0