Find new page in excel vba
In Excel VBA, you can create a new page (also known as a new worksheet) using the following methods:
Method 1: Using the Worksheets.Add
method
You can use the Worksheets.Add
method to create a new worksheet. Here's an example:
Sub CreateNewWorksheet()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets.Add
ws.Name = "New Worksheet"
End Sub
This code creates a new worksheet and names it "New Worksheet".
Method 2: Using the Sheets.Add
method
You can also use the Sheets.Add
method to create a new worksheet. Here's an example:
Sub CreateNewWorksheet()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets.Add
ws.Name = "New Worksheet"
End Sub
This code is similar to the previous example, but uses the Sheets.Add
method instead.
Method 3: Using the Application.Workbooks.Add
method
You can also use the Application.Workbooks.Add
method to create a new workbook and add a new worksheet to it. Here's an example:
Sub CreateNewWorksheet()
Dim wb As Workbook
Set wb = Application.Workbooks.Add
Dim ws As Worksheet
Set ws = wb.Sheets(1)
ws.Name = "New Worksheet"
End Sub
This code creates a new workbook, adds a new worksheet to it, and names the worksheet "New Worksheet".
Tips
-
You can also specify the position of the new worksheet by using the
After
parameter of theWorksheets.Add
method. For example:Worksheets.Add After:=Worksheets("Sheet1")
This code creates a new worksheet and adds it after the "Sheet1" worksheet.
-
You can also use the
Worksheets.Add
method to create a new worksheet with a specific template. For example:Worksheets.Add Template:="Template.xlsx"
This code creates a new worksheet with the template "Template.xlsx".