Reputation: 11
I am working in a google document spreadsheet to make a list of active customers. I am attempting to create a script that when a completion date is entered, that row (all the customer info) is transfered to another sheet and/or deleted. I started a script but it isn't working properly.
function myFunction() {
'var ssdate = spreadsheet.column B'
// the "if" clause : if (date = 1) {
// the "then" clause : then ( move row to sheet 2)
}
Since this is my first time, I am sure this needs some work, but any help would be greatly appreciated.
Upvotes: 0
Views: 4088
Reputation: 63
Please try the following example:
var ddate = Utilities.formatDate(new Date(), "GMT", "MM-dd-yy");
function checkDate(){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var rows = sheet.getDataRange();
var rowsNumber = rows.getNumRows();
var column = sheet.getDataRange();
var values = column.getValues();
for (var i = 1; i <= rowsNumber -1; i++){
var customerData = values[i];
var customerDate = customerData[2];
var myRow = Math.round(i) +1;
var conCustomerDate = Utilities.formatDate(new Date(customerDate), "GMT", "MM-dd-yy");
if (conCustomerDate > ddate){
sheet.getRange("D" + myRow).setValue("OK");
}
else {
sheet.getRange("D" + myRow).setValue("Old");
}
}
}
Upvotes: 2
Reputation: 17752
It's much easier to read the Google Apps Script tutorials and guide first. They will give you a much better quick start.
Upvotes: 2