Changing 2 worksheet name at the same time

FlipEternalX

New Member
Joined
Mar 3, 2023
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone, I have code here that changing a worksheet name. Now, I want to put "Cleaners" 1 and "Cleaners 2" for 2 worksheets and resetting/getting back to the first one after reaching the last sheet. ( not based on color)

VBA Code:
Private Sub Workbook_Open()
    Dim OriginalDate As Date
    Dim Weeks As Integer
    Dim SheetNum As Integer
    Dim sh As Worksheet
    
    
    OriginalDate = #12/31/2023#
    Weeks = DateDiff("ww", OriginalDate, Now)
    SheetNum = Weeks Mod Sheets.Count + 1
       
    If InStr(1, Sheets(SheetNum).Name, "Cleaners") < 1 Then

        'Workbook protection password
        ThisWorkbook.Unprotect "testpassword"

        For Each sh In Sheets
            sh.Name = Replace(sh.Name, " (Cleaners)", "")
        Next sh
        Sheets(SheetNum).Name = Sheets(SheetNum).Name & " (Cleaners)"
        ThisWorkbook.Protect Structure:=True, Windows:=False
    End If
End Sub

Here is the current output of the code.
1704192527410.png



I want a output like this.
1704192592842.png


Then it will go back to Jane (Cleaners 1) & Aether (Cleaners 2) again after the week have been passed for Justin, and Clare.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Seeing what you start out with would help because you might be going about this in a convoluted manner. I wonder if all you need (aside from protecting/unprotecting is
Sheets(SheetNum).Name = Sheets(SheetNum).Name & "(Cleaners " & i & ")" where you increment i in a loop. as long as the sheet number fits the requirement. I cannot recall if sheet number references get messed up if you move sheets around or insert them, so that might turn out to be an issue at some point
 
Upvote 0
Seeing what you start out with would help because you might be going about this in a convoluted manner. I wonder if all you need (aside from protecting/unprotecting is
Sheets(SheetNum).Name = Sheets(SheetNum).Name & "(Cleaners " & i & ")" where you increment i in a loop. as long as the sheet number fits the requirement. I cannot recall if sheet number references get messed up if you move sheets around or insert them, so that might turn out to be an issue at some point
Hello. Where should I put this one?
 
Upvote 0
Why are you just bumping your thread instead of providing the information that was asked for?
 
Upvote 0
Why are you just bumping your thread instead of providing the information that was asked for?
Hi Sorry, I didn't understand what you are saying on your last comment. I already get the solution. The only problem is that they are overlapping each other as I said on my last part of my post.
 
Upvote 0
OK, you're still not showing what you have to begin with so I will wish you good luck with this one.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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