SHARE
TWEET

Untitled

a guest Feb 21st, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onEdit(e){
  2.  
  3.   var range = e.range;
  4.   var colIndex = range.getColumnIndex(); //Same as getColumn()
  5.   var rowIndex = range.getRowIndex(); //Same as getRow()
  6.  
  7.   //Donde utilizar el filtro
  8.   var rangeLlista = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Llista").getRange("A6:AX500").getValues();
  9.  
  10.   //Lo que queremos borrar
  11.   var rangeBorrar = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Asignacion").getRange("A9:AX500");
  12.  
  13.   //Asignacion de las celdas que tiene que filtrar.
  14.   var RangeAsignacion = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Asignacion").getRange("A2:F2");
  15.  
  16.   //Los criterios a filtrar
  17.   var Asignacion1 = RangeAsignacion.getCell(1,2).getValue().toString();
  18.   var Asignacion2 = RangeAsignacion.getCell(1,5).getValue().toString();
  19.  
  20.   //Columna de los criterios a filtrar, la culumna A = 0
  21.   var columnIndex1 = 5;
  22.   var columnIndex2 = 6;
  23.  
  24.   //Mira si se modifican las celas que nosotros queremos
  25.   if(range.getSheet().getName() === 'Asignacion'){
  26.  
  27.     var watchRange1 = {
  28.       top : 2, // start row
  29.       bottom : 2, // end row
  30.       left : 1, // start col
  31.       right : 6, // end col
  32.     };
  33.  
  34.     if(colIndex >= watchRange1.left && colIndex <= watchRange1.right && rowIndex >= watchRange1.top && rowIndex <= watchRange1.bottom && e.Value != 0){
  35.  
  36.       //Borrado del contenido anterior
  37.       /*var start = 9;
  38.       var end = rangeBorrar.getMaxRows();
  39.  
  40.       rangeBorrar.deleteRows(start, end - start);*/
  41.  
  42.       rangeBorrar.clear({contentsOnly: true});
  43.  
  44.       //Se realiza el filtrado
  45.       var filteredData = rangeLlista.filter(function (dataRow){
  46.  
  47.         return dataRow[columnIndex1] === Asignacion1 && dataRow[columnIndex2] === Asignacion2;
  48.  
  49.       });
  50.  
  51.       var rows = filteredData.length;
  52.       var columns = filteredData[0].length;
  53.       SpreadsheetApp.getActiveSheet().getRange(9,1,rows,columns).setValues(filteredData);
  54.  
  55.     };
  56.  
  57.   };
  58.  
  59. };
  60.      
  61. var filteredData = rangeLlista.filter(function (dataRow).sort(19,true){ return dataRow[columnIndex1] === Asignacion1 && dataRow[columnIndex2] === Asignacion2; });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top