Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a new worksheet and rename it with VBA
#1
Example:

Sub CreateAndRenameSheet()
    Dim newSheet As Worksheet
   
    'Add a new worksheet and store the reference to the new sheet in the variable "newSheet"
    Set newSheet = ThisWorkbook.Sheets.Add
   
    'Rename the new worksheet to "NewSheet"
    newSheet.Name = "NewSheet"
End Sub

Explanation:

The code defines a subroutine named CreateAndRenameSheet.
It declares a variable newSheet to store the reference to the newly created worksheet.
The Sheets.Add method is used to add a new worksheet to the workbook, and the reference to the new sheet is assigned to the newSheet variable.
The Name property of the newSheet variable is set to "NewSheet" using the assignment statement (newSheet.Name = "NewSheet"), effectively renaming the newly created worksheet.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy data to another worksheet Qomplainerz 0 401 07-27-2023, 11:24 AM
Last Post: Qomplainerz
  Create a hyperlink with VBA Qomplainerz 0 411 07-27-2023, 11:10 AM
Last Post: Qomplainerz
  Create a pivot table based on data in a worksheet with VBA Qomplainerz 0 415 07-27-2023, 09:48 AM
Last Post: Qomplainerz
  Filter data in a worksheet Qomplainerz 0 383 07-27-2023, 09:46 AM
Last Post: Qomplainerz
  Create a chart from data with VBA Qomplainerz 0 382 07-27-2023, 09:44 AM
Last Post: Qomplainerz
  Protect and unprotect worksheet with VBA Qomplainerz 0 304 07-27-2023, 08:20 AM
Last Post: Qomplainerz
  Count the number of rows in a worksheet with VBA Qomplainerz 0 327 07-27-2023, 07:50 AM
Last Post: Qomplainerz
  How to create a simple message box with VBA Qomplainerz 0 265 07-27-2023, 07:27 AM
Last Post: Qomplainerz
  Worksheet methods in VBA Qomplainerz 0 283 07-26-2023, 08:44 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)