Copy Paste Data, Remove Filter, Apply Filter, Delete Filtered Data

Copy Paste Data, Remove Filter, Apply Filter, Delete Filtered Data

function UpdateRationDistributionData(){
  const ss=SpreadsheetApp.getActiveSpreadsheet();
  const sh1=ss.getSheetByName('Form Responses 1');
  const lastRow1=sh1.getDataRange().getLastRow()-1;
  const sh2=ss.getSheetByName('Ration Distribution Raw Data');
  const lastRow2=sh1.getDataRange().getLastRow()-1;

  sh2.getRange('A1').setValue('Member ID');
  sh2.getRange(2,1,lastRow2).setFormulaR1C1('="M-" & LEFT(RC[32],4) &"-" & "Ration" & "-" & REPT(0,5-LEN(ROW()-1)) & ROW()-1');

  const lastRow3=sh2.getDataRange().getLastRow();
  sh2.getRange('A1:A'+lastRow3).copyTo(sh2.getRange('A1'), SpreadsheetApp.CopyPasteType.PASTE_VALUESfalse);

  if(sh2.getFilter()!=null){
    sh2.getFilter().remove();
  }
  sh2.getRange('A1:AH'+lastRow3).createFilter();
  const criteria=SpreadsheetApp.newFilterCriteria().setHiddenValues(['New (Generate member ID in back-end)']).build();
  
  sh2.getFilter().setColumnFilterCriteria(21,criteria);
  
  sh2.getRange('A2:A'+lastRow3).clear({contentsOnlytrueskipFilteredRowstrue});
  //sh2.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});  
  sh2.getFilter().remove();

}

Comments

Popular posts from this blog

Send Email with Image/s in Mail Body Using GAS-2

Send Email with Image/s in Mail Body Using GAS-1