Creating multiple sheets

Copper Contributor

I need to name around 50 sheets and trying to find a way to do this automatically, rather than naming each sheet.

 

1 Reply

If you want each sheet to have its own custom name before creating them, you can modify the VBA code to include an array of names.

Here is an example:

VBA Code is untested; please make backup before use the code.

Sub CreateAndNameSheets()
    Dim sheetNames() As Variant
    Dim i As Integer
    
    ' Define an array of custom sheet names
    sheetNames = Array("SheetName1", "SheetName2", "SheetName3", "SheetName4", ...)

    ' Naming and creating sheets
    For i = 0 To UBound(sheetNames)
        ' Add a sheet with the specified name
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = sheetNames(i)
        
        ' Additional code for any other actions you want to perform on each sheet, if needed
    Next i
End Sub

 

In this code, replace "SheetName1", "SheetName2", etc., with the actual names you want for each sheet. The loop will go through each name in the array, create a sheet with that name, and execute any additional code you want for each sheet.

  1. Open the VBA editor (Alt + F11).
  2. Insert a new module.
  3. Paste the updated code.
  4. Run the macro (Alt + F8) and select "CreateAndNameSheets."

This way, each sheet will have its own custom name specified in the array. Adjust the code based on the specific names you want to use. AI was partially deployed to support the text.

 

My answers are voluntary and without guarantee!

 

Hope this will help you.

Was the answer useful? Mark as best response and Like it!

This will help all forum participants.