I have a tracking spreadsheet that opens up a user spreadsheet and tracks whether or not they have responded to the correct week. The user may sign up at any time, so i have an if statement that counts the number of days between today and spreadsheet creation date. It then moves it to the correct cell. I then need another if statement that says if the last update date is less than 7 days, then green if not red. Both If statements work as standalone code, but when I try to next them, the 2nd If statement is running first, putting Y or No into the cell and then it activates the correct cell based on the spreadsheet date! I need that 2nd If statement to run after it has activated the correct sheet.
I have tried moving the syntax. I have tried creating the If statement inside each If statement. The problem is going to be that the code needs to run automatically for the full 52 weeks of the year
function trackingSheetUpdate() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName('Active Campaign');
var trackSheet = ss.getSheetByName('Tracking')
var now = new Date()
var createDate = sourceSheet.getRange(2, 6).getValue()
var NoOfDays = (now - createDate) / (1000 * 60 * 60 * 24);
var diff = Math.round(NoOfDays)
Logger.log(diff);
var rowData = sourceSheet.getRange(1, 1, sourceSheet.getLastRow(), sourceSheet.getLastColumn()).getValues();
for (var i = 2; i < rowData.length; i++) {
var getUpdate = sourceSheet.getRange(i, 5).getValue();
var openSheet = SpreadsheetApp.openByUrl(getUpdate).getSheetByName('Sheet1')
var row = openSheet.getLastRow()
var weeklyUpdate = openSheet.getRange(row, 1).getValue();
var calc = (now - weeklyUpdate) / (1000 * 60 * 60 * 24)
var calcDate = Math.round(calc)
if (diff > 1 && diff <= 7) {
trackSheet.getRange(i, 2).activateAsCurrentCell()
} else if (diff > 7 && diff <= 14) {
trackSheet.getRange(i, 3).activateAsCurrentCell()
} else if (diff > 14 && diff <= 21) {
trackSheet.getRange(i, 4).activateAsCurrentCell()
}
if (calcDate <= 7) {
trackSheet.getActiveCell().setValue("Y")
} else {
trackSheet.getActiveCell().setValue("N")
}
I have set the creation date to 8/5/19, so it should go to column 2 - which it does. I have set the last update date to 8/5/19, so it should be red and No, which it is (except it puts this result into whichever cell I leave it in, then moves to column 2 and activates it!)