I have multiple sheets all with names "Pipeline History mm-dd-yyyy" with different dates. I want to search the names of the sheets for the most recent date. And then hide that sheet. I have started writing some code, but I don’t even know where to start.
This is what I’ve tried to get started with:
var allSheets = ss.getSheets();
var searchText = "Pipeline History";
var pipelineHistorySheets = allSheets.filter(s => s.getSheetName().includes(searchText));
2
Answers
Try something like this:
I have seven sheets named Sheet0 through Sheet6 and I named three them like this
Sheet0 03-01-2024, Sheet1 02-01-2024, Sheet2 01-01-2024 the others are just named Sheet3, Sheeet4, Sheet5 and Sheet6. I used the following code to find the sheet with the most recent date. Note: the most recent date has the largest valueOf();
Use a regular expression to extract the date portion in sheet names, and Array.sort() to get the most recent one, like this: