Kind of a macro noob. I’ve created a google sheets button that is meant to record the date at which the button is pressed in the next available row in column A in the sheet ‘History’ as well as copy the value of a cell (B13) from the sheet ‘Daily Tracker’ to the same row in column B. It is then meant to, with each successive click of the button, save that new information to the next row. Right now, the macro copies the date and 'Daily Tracker'!B13
to A1 and B1 over and over instead of continuing to A2:B2
, A3:B3
, etc.
Presently, I have the following macro:
function Save1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1').activate();
var date = new Date();
date.setHours(0, 0, 0, 0);
spreadsheet.getActiveRangeList().setValue(date);
spreadsheet.getRange('B1').activate();
spreadsheet.getCurrentCell().setFormula('='Daily Tracker'!B13');
};
I know that I need change the spreadsheet.getRange
with some additional variable/formula. I just don’t know what that should be.
Brach Burton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Please read Extending Google Sheets and Google Sheets Macros.
One of the key things that you should learn is that Google Apps Script uses JavaScript as a programming language, as well as the basics for reading and writing values in Google Sheets.
The above because, the code in the question doesn’t do what you say. It add the current date to the active range list. From https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getActiveRangeList()
getActiveRangeList()
Returns the list of active ranges in the active sheet or null if there are no active ranges.If there is a single range selected, this behaves as a getActiveRange() call.
The above means that the date is added to the all the active ranges rather
in the next available row in column A in the sheet ‘History’
It doesn’t do either
copy the value of a cell (B13) from the sheet ‘Daily Tracker’ to the same row in column B.
Regarding this part, what is does is to add a formula to B1.