Need help with VBA to select cell containing current week

sparkytech

Board Regular
Joined
Mar 6, 2018
Messages
96
Office Version
  1. 365
  2. 2019
My Excel workbook contains multiple sheets which are all the same template other than the data in the cells. Each sheet has dates in B:11 to BC:11 which are the dates of each Monday for the year. I need to select (jump to) the cell containing the current week whenever each sheet is opened. Example: Today is 02.16.2021, so when I open each sheet it would need to jump to cell I:11.

I am still learning VBA and have no clue how to do this. Any help would be greatly appreciated!
 

Attachments

  • Week Beginning.jpg
    Week Beginning.jpg
    66.1 KB · Views: 6

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
One way would be to use something like this in the workbook module.
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Range("C11:BC11")(Evaluate("MATCH(TODAY(),C11:BC11)")).Select
End Sub
 
Upvote 0
Solution
That works great, thanks! One more question... I have an "Admin" sheet that I want to exclude from this function. Is there a way to do that?
 
Upvote 0
Like this,
Excel Formula:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name <> "Admin" Then Range("C11:BC11")(Evaluate("MATCH(TODAY(),C11:BC11)")).Select
End Sub
If you wanted to include / exclude multiple sheets then Select Case would be easier to manage (remember that it is case sensitive as well).
 
Upvote 0
Once again, much thanks! This works great and saved me a lot of time reverse engineering. I added a line to make it scroll the current week column to the right of column "A" which is frozen. Final code below if it helps anyone else. Thanks!

VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name <> "Admin" Then Range("C11:BC11")(Evaluate("MATCH(TODAY(),C11:BC11)")).Select
ActiveWindow.ScrollColumn = ActiveCell.Column
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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