Changing the month in a sheet name

bearcub

Well-known Member
Joined
May 18, 2005
Messages
701
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I have several files that I use every month. I have two sheets which include the current month that I am working on.

For example, I'm starting the November file and I need to rename a couple of these sheets from Sept to Oct (I do commissions so we I am preparing the Oct commissions to be paid at the end of Nov).

I want to change:

Comm_Sept 2019 Brazil Summary

<------------------to-------------------->

Comm_Oct 2019 Brazil Summary

I'm would like to automate this using a macro so I don't have to update it every month (some months I miss changing the name). The current file name I'm using is

Compensation Summary - Nov 2019 - Brazil Accruals for Oct 19

I want to use the word "Oct" in the sheet name (e.g. Comm_Oct 2019 Brazil Summary from Comm_Sept 2019 Brazil Summary).

Is there a macro that change Month in the sheet name to the month in the file name?

Thank you for your help in advance,

Michael
 
OK, so the sheet names have now moved from 4-digit years to 2-digit years. :cool:

IF ..
a) The 2 relevant sheet names start with "Comm_mmm yy" or "mmm yy", and
b) No other sheet names start like that
THEN
this should work for the sheet names for any country/region

Rich (BB code):
Sub ChangeSheetName_v3()
  Dim ws As Worksheet
  Dim sNextMonth As String
  
  Const ShName1 As String = "Comm_??? ## *"
  Const ShName2 As String = "??? ## Comm_*"
  
  For Each ws In Worksheets
    With ws
      Select Case True
        Case .Name Like ShName1
          sNextMonth = Format(DateAdd("m", 1, "1 " & Mid(.Name, 6, 6)), "mmm yy")
          .Name = "Comm_" & sNextMonth & Mid(.Name, 12)
        Case .Name Like ShName2
          sNextMonth = Format(DateAdd("m", 1, "1 " & Left(.Name, 6)), "mmm yy")
          .Name = sNextMonth & Mid(.Name, 7)
      End Select
    End With
  Next ws
End Sub
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,539
Latest member
alex78

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