Go to specific sheet based on date - Google Sheets

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.

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:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top