Do I need to re-run the script to move the word Cleaners to Jayvee and remove the Cleaners from Jane?
Yes, the script must be rerun to move the word. However, . . .
Or is it automatically even if I didn't run it for next week?
it will automatically be rerun whenever you open the workbook, even if you don't open it for a week. In fact, it reruns every time you open the workbook, so multiple times per day? Multiple days in the same week? It just doesn't appear to change anything because the same sheet is reset with Cleaners.
Now that I think about it, the code I originally provided changes the sheet names even if they don't need it (they already were changed this week). In this code, it checks to see if the designated sheet needs changing. If not, nothing happens. If so, then the sheets are changed.
VBA Code:
Private Sub Workbook_Open()
Dim OriginalDate As Date
Dim Weeks As Integer
Dim SheetNum As Integer
Dim sh As Worksheet
'Change this date to be the Sunday of the first week (the first sheet to have "Cleaners" added to it)
OriginalDate = #12/24/2023#
Weeks = DateDiff("ww", OriginalDate, Now)
SheetNum = Weeks Mod Sheets.Count + 1
If InStr(1, Sheets(SheetNum).Name, "Cleaners") < 1 Then
'Change the password to the workbook protection password
ThisWorkbook.Unprotect "PA$$WORD"
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
To see what the code would do next week, pretend that you started this last week and change the date in the code to Dec. 24. Close and reopen the workbook. Since today is the "second" week now, the second sheet should now have Cleaners. Then, change the date back to today.
there are 18 people who are using this and there is 2 batch of Cleaners on this workbook,
The way the code is set up now is strictly based on the number of sheets and their order from left to right. The first sheet gets "Cleaners" today if this is week 0, the second if week 1, etc. This makes it easy if people come and go because you can simply remove or add sheets in the correct order, and the sheet name doesn't matter.
To start having 2 sheets updated requires the code to be changed. It seems easy enough to do if you base it again on the order of the sheets. If you have an even number of sheets and order the cleaners so that the two for each week are next to each other in the sheet order, the code could be changed to use sheets 1-2 the first week, 3-4 the second week, and so on. If you want any other sort of order or there is an odd number of people, then the code would need to get more busy.