How To Create A New Sheet In Excel Vba

Creating a New Sheet in Excel VBA

Here is an example of how to create a new sheet in Excel using VBA:

    
      Sub CreateNewSheet()
        Dim newSheet As Worksheet
        Set newSheet = ThisWorkbook.Sheets.Add(After:= _
          ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
        newSheet.Name = "NewSheet"
      End Sub
    
  

In this example, we start by declaring a variable called “newSheet” of type Worksheet. We then use the “Add” method to create a new sheet and assign it to the variable. The “After” parameter specifies the sheet after which the new sheet should be added, in this case, it is added after the last sheet in the workbook. We then assign a name to the new sheet using the “Name” property.

You can modify this code to customize the name of the new sheet or specify a different position for the new sheet.

Related Post

Leave a comment