Automatic Rename of a new sheet

queysoft

New Member
Joined
Aug 3, 2021
Messages
49
Office Version
  1. 2016
Platform
  1. Windows
Hi - I put this into a button to copy a template and create a new sheet. It would be nice to add in the option to type in the new sheet name with a prompt, but I don't know how to do this.
At the moment a new sheet is created with the copied templete and its called "New Person (2)" and people have to manually rename it. I would like to know if its possible to build in a prompt into the macoro that says something like "please enter the name of your new person" and the new sheet automatically renames the tab......
Does anyone else?

Sub New_data_Sheet()
'
' New_data_Sheet Macro
'
Sheets("Add Person").Select
Sheets("New Person").Visible = True
Sheets("New Person").Select
Sheets("New Person").Copy Before:=Worksheets("Sheet1")
Sheets("New Person").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("New Person (2)").Select
'

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
try this

VBA Code:
Sub New_data_Sheet()
Dim sheetName As String
sheetName = InputBox("Enter the name of the new sheet:")

If sheetName = "" Then Exit Sub

Dim newSheet As Worksheet
Set newSheet = Sheets("New Person")
newSheet.Visible = True
newSheet.Copy Before:=Worksheets("Sheet1")
newSheet.Visible = False

ActiveSheet.Name = sheetName
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top