VBA AutoOpen sub to worksheet # based upon the current month

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,107
Office Version
  1. 365
Platform
  1. Windows
Good EveningEveryone :),

I would like to create an AutoOpen sub that automatically opens up to a specific worksheet based upon the current month.



For example, we are currently in October, so I'd like it to open up toWorksheets(4).

If its November, I'd like it to open up to Worksheets(5).


If its December,I'd like it to open up to Worksheets(6).

If its January,I'd like it to open up to Worksheets(7).

.
. ( & so on continuing upon this consecutive pattern )
.

If its August,I'd like it to open up to Worksheets(14).

If its September,I'd like it to open up to Worksheets(15).



Can someone please help me?



Many thanks inadvance!

R/
pinaceous

 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try adding to 'ThisWorkbook'

Code:
Private Sub Workbook_Open()

Dim shtname As String

thismonth = Month(Now())

If thismonth = 11 Or thismonth = 12 Then
thismonth = thismonth - 6
Else
thismonth = thismonth + 6
End If

Worksheets(thismonth).Select

End Sub
 
Last edited:
Upvote 0
Hi mrshl9898,

That is short and sweet!

Thank you!
pinaceous
 
Upvote 0
I'm getting a Compile error: Wrong number of arguments or invalid property assignment, where it has highlighted "Month" in

Code:
 thismonth = Month(Now())

Any suggestions?

Thank you!
 
Upvote 0
Not sure on that.... No issues here.

Which version of Office is it? Or does anyone else have a suggestion?
 
Upvote 0
Just noticed something, try declaring thismonth

Code:
Private Sub Workbook_Open()


Dim shtname As String
Dim thismonth As Long


thismonth = Month(Now())


If thismonth = 11 Or thismonth = 12 Then
thismonth = thismonth - 6
Else
thismonth = thismonth + 6
End If


Worksheets(thismonth).Select


End Sub
 
Upvote 0
Maybe
Code:
thismonth = Month(Date)
If you still get the compile error, check that you don't have any subs, functions, or variables called "Month"
 
Upvote 0
Oh I see. I have two similar Private Sub Workbook_Open(). I can't seem to combine them because they do two different things. Any suggestions?? Can I have 2 Private Workbook_Open Subs operating at the same time?
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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