FlipEternalX
New Member
- Joined
- Mar 3, 2023
- Messages
- 24
- Office Version
- 365
- Platform
- 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)
Here is the current output of the code.
I want a output like this.
Then it will go back to Jane (Cleaners 1) & Aether (Cleaners 2) again after the week have been passed for Justin, and Clare.
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.
I want a output like this.
Then it will go back to Jane (Cleaners 1) & Aether (Cleaners 2) again after the week have been passed for Justin, and Clare.