FragaGeddon
Board Regular
- Joined
- Mar 24, 2005
- Messages
- 137
"How do you go to a specific sheet based on date?"
I've heard this asked before, while googling for an answer, and I've come up with this.
This will be based on your sheet names, etc. But you will need to add another sheet, like named Periods, Days, Weeks, based on what you need. Mine is named Periods.
The Periods sheet will look like this. Please see the example sheet for better a better view. The next cell @ Today is: should be =Today(), but for the sample sheet, I entered a random date.
What ever you name it will be adjusted in the Apps Script on the second line. You will need to adjust Period #, to whatever you have your sheets named as.
Here's a sample sheet> GoToSheetBasedOnDate
I've heard this asked before, while googling for an answer, and I've come up with this.
This will be based on your sheet names, etc. But you will need to add another sheet, like named Periods, Days, Weeks, based on what you need. Mine is named Periods.
The Periods sheet will look like this. Please see the example sheet for better a better view. The next cell @ Today is: should be =Today(), but for the sample sheet, I entered a random date.
Code:
Period Start January 2, 2022 Period 1
Today is: Jan - 13
Period 1 Jan - 29
Period 2 Feb - 26
Period 3 Mar - 26
Period 4 Apr - 23
Period 5 May - 21
Period 6 Jun - 18
Period 7 Jul - 16
Period 8 Aug - 13
Period 9 Sep - 10
Period 10 Oct - 8
Period 11 Nov - 5
Period 12 Dec - 3
Period 13 Jan - 7
What ever you name it will be adjusted in the Apps Script on the second line. You will need to adjust Period #, to whatever you have your sheets named as.
Excel Formula:
function onOpen() {
var cellValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("[B]Periods[/B]").getRange("C1").getValue();
if (cellValue == "Period 1") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 1").activate();}
if (cellValue == "Period 2") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 2").activate();}
if (cellValue == "Period 3") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 3").activate();}
if (cellValue == "Period 4") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 4").activate();}
if (cellValue == "Period 5") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 5").activate();}
if (cellValue == "Period 6") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 6").activate();}
if (cellValue == "Period 7") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 7").activate();}
if (cellValue == "Period 8") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 8").activate();}
if (cellValue == "Period 9") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 9").activate();}
if (cellValue == "Period 10") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 10").activate();}
if (cellValue == "Period 11") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 11").activate();}
if (cellValue == "Period 12") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 12").activate();}
if (cellValue == "Period 13") {SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Period 13").activate();}
}
Here's a sample sheet> GoToSheetBasedOnDate
Last edited: