# Scripts, scripts, scripts!

**URL:** <https://community.glideapps.com/t/scripts-scripts-scripts/18965>\
**Category:** Ask for Help\
**Created:** [November 26, 2020, 6:15pm UTC](https://community.glideapps.com/t/scripts-scripts-scripts/18965 "2020-11-26T18:15:21Z")\
**Posts on this page:** 1\
**Showing post:** 92

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [January 13, 2021, 7:18pm UTC](https://community.glideapps.com/t/scripts-scripts-scripts/18965/92 "2021-01-13T19:18:45Z")

</div>

Hello good sir,

I found myself in a similar situation and with the help of @Darren_Murphy we came up with this script. It will copy the _values only_ from a source sheet to a target sheet while skipping the ones you don’t want to copy yet. Hopefully this could point you in the right direction.

With a little tweaking it could delete the values from the source sheet that have already been processed. Then it would satisfy both your needs in one execution.

> **Summary**
>
> ```
> function copy_new_rows_to_database() {
> console.time('Archive');
> // Open the source sheet and read all data into an array
> var ss = SpreadsheetApp.getActiveSpreadsheet();
> var sourcesheet = ss.getSheetByName('YOURSOURCESHEET');
> var data = sourcesheet.getDataRange().getValues();
> data.shift(); // Discard the header row
> var data_rows = data.length;
> if (data[0][2] == '') { // If there is no data in the second row, assume the sheet is empty
> console.log('No Data in source sheet')
> console.timeEnd('Archive');
> return;
> }
> var archive_data = [];
> var moved_rows = [];
> 
> // Iterate through the array of data, adding any matching rows to the archive_data array
> // and tag the original row as 'Moved'
> var row = 0;
> while (row <= data_rows) {
> var rec = data[row];
> if (typeof rec == 'undefined') { // Exit as soon as we hit the first empty row
> console.log("Done at row %s", row+1);
> break;
> }
> if (rec[5] != 'ACTIVE' && rec[16] == '') { // Set condtions to continue
> archive_data.push(rec.slice(0,16));
> moved_rows.push(['Moved']);
> }
> else {
> moved_rows.push([rec[16]]);
> }
> row++;
> }
>   
> var source_sheet_rows_processed = row;
> var archive_rows = archive_data.length;
> // If we found any rows that need moving, append them to the end of the Database sheet
> // And then write the altered data array (with newly archived rows tagged), back to the source sheet
> if (archive_rows) {
> var archive_sheet = ss.getSheetByName('YOURTARGETSHEET');
> var start_row = archive_sheet.getLastRow()+1;
> archive_sheet.getRange(start_row, 1, archive_rows, 16).setValues(archive_data);
> console.log("Archived %s rows", archive_rows);
> sourcesheet.getRange(2,17,source_sheet_rows_processed, 1).setValues(moved_rows); // Start from row 2 so we don't mess with the header
> }
> else {
> console.log('No new rows to archive.');
> }
> console.timeEnd('Archive')
> }
> 
> ```

Note: If some of the data/conditions you need to execute the script live in the Glide Data Editor only, you would need to find a way to bring that logic into GSheets to use with scripts.

---

_[View the full topic](https://community.glideapps.com/t/scripts-scripts-scripts/18965)._
