Google Script: Conditionally copy rows from one sheet to another in the same spreadsheet

后端 未结 1 1160
鱼传尺愫
鱼传尺愫 2021-01-01 00:32

I read Google Script: Conditionally copy rows from one spreadsheet to another and could not make it work for me.

I need a script that will allow me to do the quoted

1条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 01:15

    C.Lang is right, this is not a place to get readymade scripts ... but since this question is so common and has been aswered so often it took me a few minutes to write and test... so there it is :

    var ss=SpreadsheetApp.getActiveSpreadsheet();// some global variables
    var master = ss.getSheetByName('All_Mileage');
    var colWidth = master.getMaxColumns();
    
    
        function copyRowsOnCondition() {
          var data = master.getDataRange().getValues();
          for(n=2;n

    EDIT : since I used the name value in MasterSheet to find destination sheet I thought it might be usefull to handle the case where the destination sheet doen't exist by creating it using the same rule, ie. name = sheetName...

    The other issue was that there was no way to know which rows had been already copied... so I made a version that handles all that, copying only the rows that are manually selected (even in only a single column) and change the background color to tell that these rows have been processed. I also added a menu for a minimal comfort ;-)

    (how to keep busy on a cold sunday afternoon ;-)

    var ss=SpreadsheetApp.getActiveSpreadsheet();
    var master = ss.getSheetByName('All_Mileage');
    var colWidth = master.getLastColumn();// last used col in masterSheet
    var sheets = ss.getSheets();// number of sheets
    
    function onOpen() {
      var menuEntries = [ {name: "Copy selected Rows to sheets", functionName: "copyRowsOnConditionV2"},
    
                         ];
      ss.addMenu("Copy functions",menuEntries);// custom menu
    }
    function copyRowsOnConditionV2() {
      var sheetNames = [];// array of existing sheet names
      var sheets = ss.getSheets();// number of sheets
      for(s=0;s

    Illustration below :

    enter image description here

    0 讨论(0)
提交回复
热议问题