Run macro across multiple worksheets - automatically open at today's date

HinaLennox

New Member
Joined
Sep 6, 2021
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I'm completely new to the world of macros, and am struggling to get a macro to apply across multiple worksheets in the one Excel file.

Basically 14/28 of the sheets feature a kind of calendar, and I'd like the sheets to always open on the column displaying today's date (so nobody needs to scroll to the date).

The following Macro works for the one sheet named in it, but when I try to duplicate it (and change the sheet name) or use a code to make it apply across all sheets, I get error messages and it doesn't work.
Can anyone help me out? Is there a way to list the names of multiple sheets in the macro?

Private Sub Workbook_Open()
Worksheets("Leela Sch").Select
x = Day(Date)
Worksheets("Leela Sch").Rows(1).Find(What:=x, LookIn:=xlValues).Activate
Application.Goto Selection, True
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to the MrExcel board!

Try this

In a standard module:
VBA Code:
Sub GoToDay()
  Dim x As Long
  Dim rFound As Range
  
  x = Day(Date)
  Set rFound = ActiveSheet.Rows(1).Find(What:=x, LookIn:=xlValues, LookAt:=xlWhole)
  If Not rFound Is Nothing Then Application.Goto rFound, True
End Sub

In the ThisWorkbook module:
VBA Code:
Private Sub Workbook_Open()
  GoToDay
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  GoToDay
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,766
Messages
6,126,761
Members
449,336
Latest member
p17tootie

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