How do I get my Macro that references 12 tabs named after each month to auto change if I change the tab names

KRE

New Member
Joined
Apr 18, 2023
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I have Macros that reference tabs that represent each month as in the screen shot below. If I change the names of the tabs for instance "dec" to "DEC24" how do I get the macro screen shot below to auto pick up that tab name?

1715357190915.png
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Maybe like
VBA Code:
Dim sht As Worksheet

If Left(sht.Name,3) = "DEC" Then
    'do something
End If
I suspect you could integrate all of those into one sub. How that would look depends on what you are doing to run any one of them. It does not look like that is a command button.
Please use code tags (vba button on forum posting toolbar) and not pictures of code.
 
Upvote 0
What I posted is not correct and I can't edit it now. That approach would be used when looping over the sheets, which may not be what you want to do.
VBA Code:
Dim sht As Worksheet

For Each sht in ThisWorkbook.Sheets
    If Left(sht.Name,3) = "DEC" Then
    'do something
End If
Next
You could also refer to the sheet by its code name instead of the sheet tab value. The code names are shown in the objects list for the vba project.
 
Upvote 0
Solution
The reference to the sheet by its code name worked! Thank you!
 
Upvote 0
Glad I could help and thanks for the recognition.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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