John Davis
Well-known Member
- Joined
- Sep 11, 2007
- Messages
- 3,457
Hello All:
How would I code the Active Sheet to be renamed Sheet1?
How would I code the Active Sheet to be renamed Sheet1?
ActiveSheet.Name = "Sheet1"
On Error GoTo Trap
ActiveSheet.Name = "Sheet1"
Trap:
If Err.Number = 1004 Then
MsgBox "There is already a sheet called Sheet1!!"
End If
That will work, but you need to be careful
Each sheet has 2 Names, The name on the Sheet Tab(Which is what you are changing with this code) and The Index Name. In a new workbook, you will have a sheet with Index Name and Sheet Name both "Sheet1". You can, using the code, change another sheet's Tab Name to "Sheet1", provided you have renamed the original "Sheet1"
So you could have 2 sheets, one with an Index Name of "Sheet1" and a Tab Name of "Sheet2" while the other might have an Index Name of 'Sheet2" and a tab name of "Sheet1"
I actually saw Bill (AKA MrExcel use this once).
The only reason I mention this is because it could become very confusing if you are trying to write VBA for the workbook
lenze
Worksheets("Sheet1").Range.......
use
Sheet1.Range......
John
Why hardcode the sheet name?