Reputation: 11
I'm very new to Javascript and Apps Script I'm looking to create a function that updates another sheet based on the date in a specific range of the active sheet. I run and there are no errors but it is not transferring the values from the active sheet to the named sheet "2022 YTD".
Please help me see what I'm not seeing.
function updateYTD() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
var copyName = sheet.getSheetName
if (copyName == "January") {
sheet.getRange("C2:D32").copyTo(ss.getSheetByName("2022 YTD").getRange("C2"),{contentsOnly:true});
}
Thanks!
Upvotes: 0
Views: 61
Reputation: 64032
Try it this way:
function updateYTD() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("January");
if (sheet) {
sheet.getRange("C2:D32").copyTo(ss.getSheetByName("2022 YTD").getRange("C2"),{contentsOnly:true});
}
}
Upvotes: 1