简体   繁体   中英

Copy range in google docs to another sheet

I have Google form that gets filled in by a few users. Works great but has it's limitations.

I'd like to copy the data entered from the active sheet to a new sheet called "work", all information except the first row that is. In the first row I have a few array formulas that populate some cells as new data is entered on the active sheet.

The second sheet (work) has a header row with all the formatting, data validation, some formulas etc (row 1). This information can not be applied when a new record is added via the form.. so I am told..

Thus, once the data has been copied from the active sheet (called active) I'd like the new data to be formatted as per the heading row (row 1) of the "work" sheet with all the formatting, validation, formulas etc being applied to the new data.

Is this doable? I am a noob when it comes to scripting so a complete solution would be highly appreciated.

here is a sample form you can play with https://docs.google.com/spreadsheet/ccc?key=0AplugTacg-08dFNRUHROSW82bDhESkxBdjVTV0NOLUE

First thing i noticed one can not just copy/paste as the array formulas will bong things up so it has to be a paste special - values only

Any help greatly appreciated.

I'm struggling a bit with the logic behind what you're doing, but I've attempted a solution in sheet 'work2' in this copy of your spreadsheet . Perhaps have a play and report back what's not right or missing.

The script is this:

function onFormSubmit(e) {
  var sheet = SpreadsheetApp.getActive().getSheetByName('work2');
  var nextRow = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 9); 
  sheet.getRange(2, 1, 1, 9).copyTo(nextRow);
  var sLength = e.values[2].length;
  var huuh = e.values[3] * sLength;
  var pending = e.values[3] * e.values[3] / huuh;
  var nextMonth = e.values[3] + pending;
  nextRow.setValues([[e.values[0], e.values[1], huuh, e.values[2], sLength, e.values[3], 'Please select action', pending, nextMonth]]);
}

and has an "on form submit" trigger attached to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM