Hello,
I have 2 questions on renaming worksheets:
1) f I tried to name the worksheet with the name of each month from January to December with code below, I got the error "Compiled error.Variable not defined". It seems that code mmmm is not read.
2) If I tried to name the worksheet with numbers from 1 to 12 with code below, all sheets are correctly renamed except the 10th one which is named "137165" instead of "10".
Any idea?
Thanks!
I have 2 questions on renaming worksheets:
1) f I tried to name the worksheet with the name of each month from January to December with code below, I got the error "Compiled error.Variable not defined". It seems that code mmmm is not read.
VBA Code:
Option Explicit
Sub RenameSheets()
' copy Sheet 1 12 times, one per month
Dim x As Integer
For x = 1 To 12
Worksheets(1).Copy After:=Worksheets(x)
Worksheets(1 + x).Name = Format(DateSerial(1, x, 1), [B]mmmm[/B])
Next x
Worksheets(1).Delete
End Sub
2) If I tried to name the worksheet with numbers from 1 to 12 with code below, all sheets are correctly renamed except the 10th one which is named "137165" instead of "10".
Any idea?
VBA Code:
Option Explicit
Sub RenameSheets()
' copy Sheet 1 12 times, one per month
Dim x As Integer
For x = 1 To 12
Worksheets(1).Copy After:=Worksheets(x)
Worksheets(1 + x).Name = Format(DateSerial(1, x, 1), x)
Next x
Worksheets(1).Delete
End Sub
Thanks!