Luke Suter
Luke Suter

Reputation: 1

Google sheets make a copy of a worksheet to drive folder

I Am wondering if anyone can help.

I have been making a collection log sheet in google sheets and i want to only make a copy of 1 of the work sheets at the end of each month.

for exaple i want this worksheet tab in google sheets called collected orders to be copyed and then the sheet to be cleared of data arfter it had been copyed to the google drive

https://i.sstatic.net/ASyyH.png

Upvotes: 0

Views: 60

Answers (1)

Antevasin
Antevasin

Reputation: 183

The Apps Script reference documentation is your friend https://developers.google.com/apps-script/reference/spreadsheet. The following code may or may not answer your question as it isn't completely clear what your actual workflow is. What the code below will do is;

  1. Get the active spreadsheet
  2. Get the sheet called Completed Orders
  3. Copy that sheet to the active spreadsheet
  4. Get the range of data on that newly copied sheet
  5. Delete the cells specified by that range of data

    function copySheetDeleteData() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var mySheet = ss.getSheetByName("Completed Orders");
    var myNewSheet = mySheet.copyTo(ss);
    var copiedData = myNewSheet.getDataRange()
    copiedData.deleteCells(SpreadsheetApp.Dimension.ROWS)
    }
    

When I read your question I think;

  • Does he want to schedule this script to run at the end of the month?
  • Does the spreadsheet need to be open at the time?
  • When he says worksheet, does he mean the spreadsheet or the sheet within a spreadsheet?
  • Why bother copying the sheet and the data and then delete the data?
  • Why not just create a new sheet and call it what you want?

Upvotes: 1

Related Questions