Hi all,
I have some code that creates a new sheet and names it what ever the user enters into an InputBox.
It works when they enter a name.
It works when they click 'Cancel'.
But it returns a “Run-time error ‘9’@: Subscript out of range” error if you click OK without entering anything in the InputBox.
How do I stop it/loop it back after the ‘If Response = "" Then” section because it’s trying to create a sheet without a name!
I can't get my head around it! I'm trying to teach myself VBA but it's going very slowly.
![]()
Sub AddNewSheet() Sheets("Template").Visible = True Sheets("Template").Copy After:=Worksheets(Worksheets.Count) Sheets("Template").Visible = False Response = Application.InputBox("Enter the technician's name:") If Response = False Then Application.DisplayAlerts = False Sheets("Template (2)").Delete Sheets("Main").Select End If If Response = "" Then MsgBox "Please enter a technician's name." Application.DisplayAlerts = False Sheets("Template (2)").Delete Sheets("Main").Select End If If Response <> False Then Sheets("Template (2)").Name = Response End If End Sub
Bookmarks