I am trying to index my google sheet, based on an if condition. So, if the 3 column data is not empty, I want the first column of the sheet to get indexed. In the code below, the if statement is working fine, but I am unable to set the value of index in the first column.
var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("production");
var data = sheetFrom.getDataRange().getValues();
var count = 0;
var farmerCount = 0;
for(n=3;n<data.length;++n){ // iterate in the array, row by row
if (data[n][2]!=""){
farmerCount++;
data[n][0].setValue(farmerCount);
//sheetFrom.getRange(n, 0).setValue(farmerCount);
}
Thanks in advance.
Range indexing in Google Apps Script is 1 based so you want to use
sheetFrom.getRange(n, 1).setValue(farmerCount);
Possibly n+1 depending on how many header rows you have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With