Create new worksheet in excel vba

You can create a new worksheet in Excel VBA using the following code:

Sub CreateNewWorksheet()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets.Add
    ws.Name = "New Worksheet"
End Sub

This code will create a new worksheet and name it "New Worksheet". You can change the name to whatever you want.

Here's how you can use this code:

  1. Open the Visual Basic Editor in Excel by pressing Alt + F11 or by navigating to Developer tab and clicking on Visual Basic.
  2. In the Visual Basic Editor, click on Insert > Module to insert a new module.
  3. Paste the code into the module.
  4. Click Run > Run Sub/User Form or press F5 to run the code.
  5. A new worksheet will be created and named "New Worksheet".

Note: The ThisWorkbook.Worksheets.Add method adds a new worksheet at the end of the workbook. If you want to add a new worksheet at a specific position, you can use the Insert method instead:

Set ws = ThisWorkbook.Worksheets.Insert(after:=ThisWorkbook.Worksheets("Existing Worksheet"))

Replace "Existing Worksheet" with the name of the worksheet where you want to add the new worksheet.