Macro to copy sheet, rename from list, and skip duplicate

jlgrunsky

New Member
Joined
Nov 3, 2016
Messages
11
Hi all,

I am new to the forum. I have been using it for excel help for years and never had a need to ask my own question until now. I have searched high and low for the answer to this. I am sure it is simple, but I cant find it anywhere.

I have an excel macro that is duplicating a template and renaming the tabs from a list. What I would like, is to be able to run the macro more than once (i.e. if someone adds to the list) without getting a bug error. So, I need to add to this macro to tell excel to just overlook the duplicates and keep going until it gets to the next unique name.

Can someone please help me? Here is my code:

Code:
Sub CreateSheetsFromAList()
Dim MyCell, MyRange As Range
Set MyRange = Sheets("Opportunity Pipeline").Range("A3")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Sheets("Template").Visible = True
For Each MyCell In MyRange
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = MyCell.Value ' renames the new worksheet
   
Next MyCell
Sheets("Template").Visible = False
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I suggest you have the script clear the range at the end. To have the script keep running over the same range of sheet names and ignore the duplicates is not a good way to do things.
 
Upvote 0
I suggest you have the script clear the range at the end. To have the script keep running over the same range of sheet names and ignore the duplicates is not a good way to do things.

Sure, I'm open to trying that. Can you tell me how to add that to my code? Thanks.
 
Upvote 0
Try this:
Code:
Sub CreateSheetsFromAList()
Dim MyCell, MyRange As Range
Set MyRange = Sheets("Opportunity Pipeline").Range("A3")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Sheets("Template").Visible = True
For Each MyCell In MyRange
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = MyCell.Value ' renames the new worksheet
   
Next MyCell
MyRange.ClearContents
Sheets("Template").Visible = False
End Sub
 
Upvote 0
Try this:
Code:
Sub CreateSheetsFromAList()
Dim MyCell, MyRange As Range
Set MyRange = Sheets("Opportunity Pipeline").Range("A3")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Sheets("Template").Visible = True
For Each MyCell In MyRange
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = MyCell.Value ' renames the new worksheet
   
Next MyCell
MyRange.ClearContents
Sheets("Template").Visible = False
End Sub

Ah, now I see what you meant. That works, thank you, but the problem is that I am using that list for other reports so I need it to stay put. With that said, I revert back to my original request. Any other ideas?
 
Upvote 0
I have no other suggestion. But if your wanting to create new sheets from a list of values you need to find some other place to put and refer to to create new sheets.
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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