Overlapping changing worksheet name

FlipEternalX

New Member
Joined
Mar 3, 2023
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi, Good day everyone.

I have concern here.

I do not want to overlap the changing of worksheet name to another color. (not based on color its just a reference)

1704259915664.png


So once I run the code, since Justin (Cleaners 1) is the last. It should be moved back to Jane, the same with Orange Tab, since Clare is the last I do not want to overlap it with Jane also, and it will get back to Aether.

Can anyone help me? Thank you so much.

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

        'Workbook protection password
       ' ThisWorkbook.Unprotect "testpassword"

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

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,076
Messages
6,122,987
Members
449,093
Latest member
Mr Hughes

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