Auto formatting worksheets

  • Thread starter Thread starter Bert
  • Start date Start date
B

Bert

Good Day, Could anyone tell me if it is possible to name worksheets
automatically;e.g., January - December. Thanks for your help, Bert.



------------------------------------------------




------------------------------------------------
 
Does automatically include a macro?

And does it mean you want 12 new sheets or rename existing sheets?

This adds 12 sheets and names them:

Option Explicit
Sub testme01()
Dim iCtr As Long

For iCtr = 1 To 12
Worksheets.Add after:=Worksheets(Worksheets.Count)
On Error Resume Next
ActiveSheet.Name = Format(DateSerial(2003, iCtr, 1), "mmmm")
'ActiveSheet.Name = MonthName(Month:=iCtr, abbreviate:=False)
If Err.Number <> 0 Then
MsgBox "Trouble with " & ActiveSheet.Name
Err.Clear
End If
Next iCtr

End Sub

Monthname was added in xl2002 (IIRC).

If you wanted to name existing worksheets, this'll do it, but it'll name them
from the leftmost to the rightmost.

Option Explicit
Sub testme01()
Dim iCtr As Long

If Worksheets.Count < 12 Then
MsgBox "Not enough worksheets"
Exit Sub
End If

For iCtr = 1 To 12
On Error Resume Next
Worksheets(iCtr).Name = Format(DateSerial(2003, iCtr, 1), "mmmm")
'Worksheets(iCtr).Name = MonthName(Month:=iCtr, abbreviate:=False)
If Err.Number <> 0 Then
MsgBox "Trouble with " & Worksheets(iCtr).Name
Err.Clear
End If
Next iCtr

End Sub

======
Depending on what you're doing, you may want to just create one workbook with
all 12 worksheets nicely named. Then use that as a master for subsequent
workbooks.
 
Back
Top