Skip to main content

Worksheet.Name property

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Returns or sets a String value that represents the object name.

Syntax

expression.Name

expression A variable that represents a Worksheet object.

Remarks

The value that you see in the cell to the right of (Name) in the Properties window is the code name of the selected object. At design time, you can change the code name of an object by changing this value. You cannot programmatically change this property at runtime.

The code name for an object can be used in place of an expression that returns the object. For example, if the code name for worksheet one is Sheet1, the following expressions are identical.

Worksheets(1).Range("a1") 
Sheet1.Range("a1")

It's possible for the sheet name to be different from the code name. When you create a sheet, the sheet name and code name are the same, but changing the sheet name doesn't change the code name, and changing the code name (by using the Properties window in the Visual Basic Editor) doesn't change the sheet name.

Example

The following code example sets the name of the active worksheet equal to today's date.

ActiveSheet.Name = Format(Now(), "dd-mm-yyyy")

The following code example sets the name of the active worksheet equal to a value from a cell.

ActiveSheet.Name = ActiveSheet.Range("A1").Value

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>