In Googlesheet I wanted to select certain rows based on the date. I am aware of the getRange() function but not aware as to how to add condition to this function. For example if I have 10 rows in the spreadsheet out of which:
- Two rows are having a date column with date of 01/01/2019.
- Three rows are having a date column with date of 01/07/2019.
- Remaining five rows are having a date column with date of 01/20/2019.
I am try to get a way to write google sheet script to pull all rows having date column between 12/31/2018 and 01/09/2019 and I should get five rows in this particular case.
I have written the below code to create a new sheet but didnt know how to select the range with condition :
var spreadsheet = SpreadsheetApp.getActive();
var sheets = spreadsheet.getSheets();
var mainSheet = sheets[0];
var fileName = mainSheet.getRange("B2:C2").getDisplayValue();
var date = Utilities.formatDate(new Date(), "GMT+5", "yyyy-MM-dd")
var newFileName = "WS_"+date;
var dataSheetFileList = DriveApp.getFilesByName(fileName);
var dataSheetFile = dataSheetFileList.next();
dataSheetFile.makeCopy(newFileName)
var newFileUrl = DriveApp.getFilesByName(newFileName).next().getUrl();
var newFile = DriveApp.getFilesByName(newFileName);
newFile.next().setSharing(DriveApp.Access.DOMAIN_WITH_LINK, DriveApp.Permission.EDIT);
var dataSheetFileList = DriveApp.getFilesByName(newFileName);
if(dataSheetFileList.hasNext()){
var dataSheetFile = dataSheetFileList.next();
var dataSheet = SpreadsheetApp.open(dataSheetFile);
var dataSheetList = dataSheet.getSheets();
var dataSheetCcb = dataSheetList[0];
**<Code to select the rows based on date>**
}
Sample Input Google Sheet Data
I am intending to automaticlally create a Summary Google Sheet(screenshot below) using the above Sample Google Sheet :