Create new sheet vba
Here is an example of how to create a new sheet in Excel using VBA:
Method 1: Using the Worksheets.Add
method
You can use the Worksheets.Add
method to create a new sheet. Here is an example:
Sub CreateNewSheet()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets.Add
ws.Name = "NewSheet"
End Sub
This code creates a new sheet and names it "NewSheet".
Method 2: Using the Sheets.Add
method
You can also use the Sheets.Add
method to create a new sheet. Here is an example:
Sub CreateNewSheet()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets.Add
ws.Name = "NewSheet"
End Sub
This code is similar to the previous example, but uses the Sheets.Add
method instead of Worksheets.Add
.
Method 3: Using the Application.Workbooks.Add
method
You can also use the Application.Workbooks.Add
method to create a new workbook and then add a new sheet to it. Here is an example:
Sub CreateNewSheet()
Dim wb As Workbook
Set wb = Application.Workbooks.Add
Dim ws As Worksheet
Set ws = wb.Sheets(1)
ws.Name = "NewSheet"
End Sub
This code creates a new workbook, adds a new sheet to it, and names the sheet "NewSheet".
Tips and Variations
- You can customize the new sheet by setting its properties, such as the sheet's tab color, font, and formatting.
- You can also use the
Worksheets.Add
method to create a new sheet at a specific position in the workbook. For example:Sub CreateNewSheet() Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets("Sheet1")) ws.Name = "NewSheet" End Sub
This code creates a new sheet after the "Sheet1" sheet.