My question pick up date and write in the following empty line? I want to copy a data from a fixed cell to a database and that it always comes under the last line.

For example, Data from cell A1 from sheet1 and write on sheet2 in D1 and then a month later the data from A1 from sheet1 write on sheet2 in D2 ectect. The data from D1 must not change when we put de data in D2

I have a script but it does not work at all

/** @OnlyCurrentDoc */

function myFunction() {
var spreadsheet = SpreadsheetApp.getActive();
  • Macro recording requires practice. Try again. By the other hand automatically doing something every month could require a Google Apps Script time-driven installable trigger.
    – Rubén
    Jul 19, 2018 at 23:08

1 Answer 1


Copying the data from the fixed cell

This is the simple part, but you can do it slightly differently from what you have posted:

var spreadsheet = SpreadsheetApp.getSheetByName('Sheet1');
var cellValue = spreadsheet.getRange('A1').getValue();

This will do two things:

  1. Get the exact tab (sheet1) that you want to get the value from, rather than whichever tab was last active
  2. Capture that value without moving the active "cursor" around the sheet by grabbing that Cell object and storing the value within

For setting the next cell on Sheet2

My assumption is that you want to go down column D and find the last entered value. Then copy the new value below that? (let me know if this is incorrect) There are a few ways to do this, depending if you have empty cells in that column, if this will always be the lowest row on that sheet populated, etc. The following is a simple way if it's always the last row of data on the sheet:

var rowToUpdate = spreadsheet.getLastRow() + 1; //Gets the row after the last row on that sheet with data
spreadsheet.getRange("D" + rowToUpdate).setValue(cellValue); //Sets the value to the next row to the value we grabbed earlier
  • Tanks for your reply, how can i make the range taller? For both where the data is removed and where it is placed?
    – Dijkgraaf
    Jul 20, 2018 at 8:45
  • Tanks for your reply, how can i make the range taller? For both where the data is removed and where it is placed? –
    – Dijkgraaf
    Jul 20, 2018 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.