0

This is my script. I need to populate the values in I2:I range when the cell value of C2 changes. I have created an array_temp but these are not getting pasted in I2. Can anybody please help me throw some light on it?

function onEdit(e) {
  var spreadsheet = SpreadsheetApp.getActive();
  var ss = e.getSheetByName('UserInterface');
  var count = ss.getRange("H2").setFormula('=countif(TalukaName!B:B,UserInterface!C2)').getValue();
  var DistrictName = ss.getRange('C2').getValue(); 
  var matchindex = ss.getRange('H3').setFormula('=match(C2,TalukaName!B:B,0)').getValue(); 
  var indexvalue = ss.getRange('H4').setFormula('=index(TalukaName!B:B,H3)').getValue(); 
  var array = [] ;
  ss.getRange('F2').clearcontent;
  var ssTaluka= e.getSheetByName('TalukaName');  
  var range = ssTaluka.getDataRange();
  var data = range.getValues();

  for (var i = 0; i < count; i++) {
    array[i]=  data[i + matchindex - 1][0]; 
  }
  var array_temp = [];
  for (var j = 0; j < array.length; j++) {
    array_temp.push([
      array[j]   
    ])
  } 

  ss.getRange('I2:I').clearContent();            
  ss.getRange('I2:I'+ (count+1)).setValues(array_temp) ; 
}
tehhowch
  • 9,645
  • 4
  • 24
  • 42
  • 1
    Possible duplicate of [Creating and Sending sheets in the same function](https://stackoverflow.com/questions/48304224/creating-and-sending-sheets-in-the-same-function) – tehhowch Oct 12 '18 at 13:42
  • See Ruben's answer and the associated documentation. You are clearing a range, and setting the values of that same range - you need to explicitly force one to be before the other. – tehhowch Oct 12 '18 at 13:43
  • Thanks. I used SpreadsheetApp.flush() but that does not seem to resolve the issue after clearing the contents before setting the array values in the range of cells but still doesnt seem to solve the issue. – Sanjyot Salgar Patkar Oct 14 '18 at 04:54
  • Then edit your question accordingly – tehhowch Oct 14 '18 at 12:36

0 Answers0