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
 
You already have sheets called Nov & Dec. Hence the problem
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
That is what is confusing me. The Nov and Dec sheets are supposed to be sheets 8 and 9. So, the code is shuffling those tabs names.
 
Upvote 0
Have a look at the last two sheets (ie 21 & 22)
 
Upvote 0
Okay. I deleted those tab names as well as the code.... Renamed the last two tabs and it works fine now.
Thank you very much for your time.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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