VBA: Copy different sheet in same workbook multiple times, naming according to list in cells

RichCowell

Board Regular
Joined
Dec 5, 2013
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I've found a VBA script to duplicate the current active worksheet, but I need to copy a different worksheet in the workbook X amount of times (X = number in a cell).

e.g.
Active Worksheet Name: Start
Worksheet to be copied: Master
Copied X times where X = Start!A10
Names of worksheets: Start!B10:B25

Can anyone help me out? I had assumed it would need to be done in two stages - replicating the Master sheet, then renaming them - but I was going to (try to) cross that bridge when I got the first bit done.

Thanks,

Rick
 
Try this to solve the hidden sheet issue:
Code:
Sub Copy_Master()
'Modified  7/22/2019  7:33:00 AM  EDT
On Error GoTo M
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets("Start").Cells(Rows.Count, "B").End(xlUp).Row
Sheets("Master").Visible = True
For i = 1 To Lastrow
    Sheets("Master").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = Sheets("Start").Cells(i, "B").Value
Next
Application.ScreenUpdating = True
Sheets("Master").Visible = False
Exit Sub
M:
MsgBox "That sheet name may already be used or you made some mistake"
End Sub
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If you get a message saying there was a error.
You may be using a duplicate name
No two sheets can have the same name
Or you may be trying to name a sheet a improper name.
Excel does not like some characters in a sheet name.

Like it does not like:


7/7/2019

It will accept
7-7-2019

And there may be more characters it does not like.
 
Upvote 0
Thanks! Works perfectly again... It's only going to be forenames in the list so shouldn't ever include incomatible characters
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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