Force to open today’s date sheet while opening a workbook.

kajee

New Member
Joined
Feb 17, 2021
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
I have a workbook of “monthly employees schedule” for a month. Each sheet cel C2 has date like feb-16, feb-17’ feb-18, feb-19......
I want force it to open today’s sheet like today is feb-18 while opening workbook.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
In ThisWorkbook (not normal macro module), put this code

VBA Code:
Private Sub Workbook_Open()

Dim strShtName As String
Dim ws As Worksheet

strShtName = MonthName(Month(Date), True) & "-" & Day(Date)

For Each ws In Sheets
    If ws.Name = strShtName Then
        ws.Activate
    End If
Next

End Sub
 
Upvote 0
Each sheet cel C2 has date like feb-16, feb-17’ feb-18, feb-19
Is the name of each sheet the same as the value in C2?
If not, how are the sheets named?

Also, are those dates in C2 actual dates (numbers) or text values?
 
Upvote 0
Thanks @Peter_SSs. My mistake. I thought I read each sheet has tab named as Feb-16, Feb-17, etc ?
 
Upvote 0
I have a workbook of “monthly employees schedule” for a month. Each sheet cel C2 has date like feb-16, feb-17’ feb-18, feb-19......
I want force it to open today’s sheet like today is feb-18 while opening workbook.
Can you please tell us if the C2 is date formatted or just a text entry?
 
Upvote 0
Date format
Just put the code below in ThisWorkbook as before

Once the workbook is opened, the sheet with same date will be activated or selected automatically

VBA Code:
Private Sub Workbook_Open()

Dim ws As Worksheet

For Each ws In Sheets
    If ws.Range("C2") = Date Then
        ws.Activate
    End If
Next

End Sub
 
Upvote 0
Just put the code below in ThisWorkbook as before

Once the workbook is opened, the sheet with same date will be activated or selected automatically

VBA Code:
Private Sub Workbook_Open()

Dim ws As Worksheet

For Each ws In Sheets
    If ws.Range("C2") = Date Then
        ws.Activate
    End If
Next

End Sub
Sorry still didn’t work for me.
 

Attachments

  • ddda.PNG
    ddda.PNG
    105.3 KB · Views: 11
Upvote 0
Sorry still didn’t work for me.
That gives helpers nothing to go on. ;)
Did it ..
- give an error message? (what message and on what line of code?)
- open up and activate the wrong sheet? (What was the date when you ran it and what sheet did it activate)
- do nothing?
- something else?

You also didn't directly address my questions about the sheet names, however, I can see them in the image in which case you could try this Wokbook_Open event code instead.

VBA Code:
Private Sub Workbook_Open()
  On Error Resume Next
  Sheets(Format(Date, "mmm dd")).Activate
End Sub

As Zot noted, this code must go in the ThisWorkbook module as shown below.

1613689933034.png
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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