[Solved] Need a VBA Code to Name Sheets

Hello Momo,

You can use a simple VBA macro to rename sheets with the names of the months automatically.
  • Go to the Developer tab >> select Visual Basic.
  • Click Insert menu >> select Module.
  • Copy-paste the following VBA code.
Code:
Sub RenameSheetsToMonths()
    Dim i As Integer
    Dim monthNames As Variant
    monthNames = Array("January", "February", "March", "April", "May", "June", _
                       "July", "August", "September", "October", "November", "December")
    
    For i = 1 To 12
        If ThisWorkbook.Sheets.Count >= i Then
            ThisWorkbook.Sheets(i).Name = monthNames(i - 1)
        Else
            ' Add new sheet if not enough
            ThisWorkbook.Sheets.Add After:=Sheets(ThisWorkbook.Sheets.Count)
            ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = monthNames(i - 1)
        End If
    Next i
End Sub
 

Online statistics

Members online
1
Guests online
102
Total visitors
103

Forum statistics

Threads
436
Messages
1,932
Members
1,111
Latest member
thaichamtangtruong
Back
Top