How To Add New Sheet In Excel Using Vba

How to Add New Sheet in Excel Using VBA

To add a new sheet in Excel using VBA (Visual Basic for Applications), you can use the following code:


    Sub AddNewSheet()
        Sheets.Add
    End Sub
  

In the above code, the “Sheets.Add” statement adds a new worksheet at the end of the existing worksheets in the workbook.

If you want to add a new sheet with a specific name, you can modify the code as follows:


    Sub AddNewSheetWithName()
        Sheets.Add.Name = "New Sheet"
    End Sub
  

In this code, the “Name” property of the new sheet is set to “New Sheet”. You can replace “New Sheet” with any desired name for the new sheet.

Here’s a complete example that demonstrates adding a new sheet and renaming it:


    Sub AddNewSheetAndRename()
        Dim ws As Worksheet
        Set ws = Sheets.Add
        ws.Name = "New Sheet"
    End Sub
  

In this code, a new worksheet is added using the “Set” statement and assigned to the variable “ws”. Then, the “Name” property of “ws” is set to “New Sheet”.

Same cateogry post

Leave a comment