Macro to copy a sheet and rename it but first check that names not been used before

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I would like a macro that will copy sheets "Master" (to the end is fine).
and rename it the name in Sheets "Welcome" O19

but before you copy the sheet i'd like to check that the name in Sheets "Welcome" O19 hasn't already been used as a tab name,
if it has cancel and messagebox " That name has already been used!"

if the copy goes ahead then
then copy the data in Sheets "Welcome" O19:O21 to copied sheet T4:T6

please help if you can thanks

Tony
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
For Example

VBA Code:
Sub jec()
 If Evaluate("iserr('Welcome O19'!A1)") Then
    Sheets("Master").Copy Sheets(Sheets.Count)
    ActiveSheet.Name = "Welcome O19"
 Else
    MsgBox "name already in use"
 End If
End Sub
 
Upvote 0
Hi JEC !​
What could happen if the worksheet already exists and its cell A1 contains an error ?!​
The reason why it's better to use the worksheet function ISREF rather than ISERR …​
 
Upvote 0
You are right! Thanks!?
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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