Balrajss0121
New Member
- Joined
- May 6, 2020
- Messages
- 11
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi, I am fairly new to vba and am trying to work through a spreadsheet. At the moment I have managed to create a macro via vba as shown below. It currently works via pressing the required button and an input box being displayed which asks for the name of the new sheet to be created. The new sheet is copied from a hidden sheet called "MASTER SHEET". The issue I am having is that when I press cancel or the close button on the input box, a new sheet is still created given the name MASTER SHEET(1) etc. Any help would be appreciated in rectifying the issue
The code is as follows:
Sub CopySheetAndRename()
Dim ActNm As String
Application.ScreenUpdating = False
On Error Resume Next
ActiveWorkbook.Sheets("MASTER SHEET").Visible = True
ActiveWorkbook.Sheets("MASTER SHEET").Copy _
after:=ActiveWorkbook.Sheets("MASTER SHEET")
ActNm = ActiveSheet.Name
ActiveSheet.Name = InputBox("Enter the name for the new sheet.")
Sheets(ActiveSheet.Name).Visible = True
ActiveWorkbook.Sheets("MASTER SHEET").Visible = False
Application.ScreenUpdating = True
End Sub
The code is as follows:
Sub CopySheetAndRename()
Dim ActNm As String
Application.ScreenUpdating = False
On Error Resume Next
ActiveWorkbook.Sheets("MASTER SHEET").Visible = True
ActiveWorkbook.Sheets("MASTER SHEET").Copy _
after:=ActiveWorkbook.Sheets("MASTER SHEET")
ActNm = ActiveSheet.Name
ActiveSheet.Name = InputBox("Enter the name for the new sheet.")
Sheets(ActiveSheet.Name).Visible = True
ActiveWorkbook.Sheets("MASTER SHEET").Visible = False
Application.ScreenUpdating = True
End Sub