Reputation: 163
I am writing a very simple macro in Google Sheets to get the month value and write it in a cell on the sheet. But for some reason the month value is not getting written to the cell.
function Macro1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'), true);
var today = new Date;
var prevMonth = Utilities.formatDate(today, 'GMT+1', 'MMMM yy');
var cell = spreadsheet.getRange('G12');
cell.setValue = prevMonth;
Logger.log(prevMonth);
Logger.log(cell.getValue());
};
I can see the value of prevMonth in the log. It is correct but no value is getting written in the actual cell and hence, the last line also returns blank. And yes, I have read-write access on the sheet.
Upvotes: 0
Views: 875
Reputation: 337
setValue is a function, so you need to pass parameter to it.
function Macro1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'), true);
var today = new Date();
var prevMonth = Utilities.formatDate(today, 'GMT+1', 'MMMM yy');
var cell = spreadsheet.getRange('G12');
cell.setValue(prevMonth);
Logger.log(prevMonth);
Logger.log(cell.getValue());
}
cell.setValue(prevMonth);
Upvotes: 4