Reputation: 45
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 "Feb".
Please help me see what I'm not seeing.
function updateYTD3() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("January");
const targetSheet = ss.getSheetByName("Feb");
if (sheet && targetSheet) {
if(sheet.getRange("A2:D32").getValues().length > 0){
sheet.getRange("A2:D32").copyTo(targetSheet.getRange("C2"),{contentsOnly:true});
}
}
}
but with funcition Loop and copy range based on criteria
but with funcition Loop and copy range based on criteria link
Upvotes: 0
Views: 60
Reputation: 10242
The script is working just fine! But it overwrites previous data since it's stated to write it in C2. Do you expect to stack the values with the previous one?
Try changing "C2"
with "C"+(targetSheet.getLastRow()+1)
Upvotes: 1