AlexisChch
New Member
- Joined
- Jul 3, 2022
- Messages
- 3
- Office Version
- 365
- 2021
- 2019
- Platform
- Windows
Hi all,
I'm new to this forum.
It seems simple but I've searched a lot online and couldn't find something that works. I searched a lot in this forum and I found lot of suggestions but nothing worked for my case.
I'm trying to copy a template worksheet (called "Template") and rename it using a command button. I have managed to achieve this.
However, I would like to rename the new worksheet only if the name is not already exists.
If the name of the worksheet exists already in another worksheet I would like to
Right now I have this code:
This code works exactly as I want. What it does is:
I would like when I click the command button to get a pop up message if the worksheet name already exists in the spreadsheet.
*PS. The "With ..End With" part of the code above works as I want but is irrelevant to my question. I put it there so I can get a pop up message when a user is trying to insert a new entry without filling the "B17" cell from the "Front Sheet".
Any help would be much appreciated.
Many thanks
I'm new to this forum.
It seems simple but I've searched a lot online and couldn't find something that works. I searched a lot in this forum and I found lot of suggestions but nothing worked for my case.
I'm trying to copy a template worksheet (called "Template") and rename it using a command button. I have managed to achieve this.
However, I would like to rename the new worksheet only if the name is not already exists.
If the name of the worksheet exists already in another worksheet I would like to
- get a pop up message saying something like this: "Entry 01 already exists, please exit and insert Entry 02" and then
- I would like the code to prevent from creating a copy of the "Template".
Right now I have this code:
VBA Code:
Private Sub cmdSV1_Click()
With Sheets("Front Sheet")
If .Range("B17") = "" Then
MsgBox "Please enter the Site Visit reference number in cell B17 before you 'Insert the Entry'"
.Activate
.Range("B17").Select
Exit Sub
End If
End With
Sheets("Template").Copy After:=Sheets("Front Sheet")
ActiveSheet.Name = Sheets("Front Sheet").Range("B17")
End Sub
This code works exactly as I want. What it does is:
- Creates a new worksheet based on a copy of the "Template" worksheet
- rename the worksheet to what is in range("B17") of the "Front Sheet" Worksheet (Range B17 is always the number "1").
I would like when I click the command button to get a pop up message if the worksheet name already exists in the spreadsheet.
*PS. The "With ..End With" part of the code above works as I want but is irrelevant to my question. I put it there so I can get a pop up message when a user is trying to insert a new entry without filling the "B17" cell from the "Front Sheet".
Any help would be much appreciated.
Many thanks