Debug tabs name to correspond with cell value.

mrjinx007

Board Regular
Joined
Jul 28, 2011
Messages
51
Hi,
I have this code that worked in another program but now that I use it in a new one, it converts all the tab names to dates except for the last three ones. The only thing that I changed was the tabs number. The old one was from 11-22 this one is 9-20
Code:
Private Sub Worksheet_Change(ByVal Target As Range)    If Intersect(Target, Range("AB2")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Dim x As Long, y As Long
    y = 0
    For x = 9 To 20
        Sheets(x).Name = "Sheet" & x
    Next x
    For x = 9 To 20
    
        Sheets(x).Name = Replace(DateAdd("m", y, Range("AB2").Value), "/", "-")
        Sheets(x).Name = Left(MonthName(Month(Sheets(x).Name)), 3)
        y = y + 1
    Next x
    Application.ScreenUpdating = True
End Sub
The debug highlights this part of the code:
Code:
Sheets(x).Name = Left(MonthName(Month(Sheets(x).Name)), 3)
Thank you
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What is the name of the sheet when you get the error?
 
Upvote 0
The code has already changed that sheet name, what is the name of sheets(x) when the error occurs?
Also what is the error number & message?
 
Last edited:
Upvote 0
Sheet13(11/1/2019)
1004 Run time error. Can not rename a sheet to the same name as another sheet,....
 
Upvote 0
The error message is telling you that you already have a sheet called Jan or Nov depending on your date format
 
Upvote 0
Yes, you can upload to dropbox & provide the link in the thread
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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