I created a Macro with a button that copies a hidden master sheet, then prompts the user to enter a sheet name with an input box. The button works if the user puts in a name, but if they press cancel, exit out, or just press OK, without a name; the macro goes to the code with an error. When I try to troubleshoot the issue I can only find ways to have the macro copy the sheet and name it Master (2). The problem is the Macro creates a copy first, then the input box appears.
Possible solutions:
Sub Macro7()
'
' Macro7 Macro
'
' Keyboard Shortcut: Ctrl+n
'
Application.ScreenUpdating = False
Sheets("Measure (master)").Visible = True
Sheets("Measure (master)").Select
Sheets("Measure (master)").Copy Before:=Sheets("Measure (Master)")
Sheets("Measure (master) (2)").Name = InputBox("Sheet Name", "Enter sheet name", "")
Sheets("Measure (master)").Select
ActiveWindow.SelectedSheets.Visible = False
Application.ScreenUpdating = True
End Sub
Possible solutions:
- Undo the actions the Macro already accomplished
- Name the sheet for the user. This would be the desired solution, but I cant figure out a way to have VBA select the proper name. It is just a string of numerical names: M1,M2,M3...
Sub Macro7()
'
' Macro7 Macro
'
' Keyboard Shortcut: Ctrl+n
'
Application.ScreenUpdating = False
Sheets("Measure (master)").Visible = True
Sheets("Measure (master)").Select
Sheets("Measure (master)").Copy Before:=Sheets("Measure (Master)")
Sheets("Measure (master) (2)").Name = InputBox("Sheet Name", "Enter sheet name", "")
Sheets("Measure (master)").Select
ActiveWindow.SelectedSheets.Visible = False
Application.ScreenUpdating = True
End Sub