-
Solved: Copying coded worksheets
I have a workbook with a sheet with VBA code attached. I now wish to create up to 25 additional sheets within the same workbook with the same code.
If I do a paste special "all" the format is fine but it has no code attached
What is the quickest way to make duplicate sheets within the same workbook?
-
[vba]Sub copies()
Dim ws As Worksheet
Set ws = ActiveSheet
For i = 1 To InputBox("Enter number of copied")
ws.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Sheet" & Sheets.Count
Next
Set ws = Nothing
End Sub
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Thanks mdmackillop,
I'm assuming I copy this code into the first worksheet and then when I create a new sheet all the code will be in place? or is this a bit too simplistic?
Thanks, Peter.
-
Hi Peter,
Copy my code into a standard module. Run it from the worksheet you wish to duplicate. You don't need 25 copies of my code. If you need an example, let me know.
Regards
MD
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Thanks MD,
That makes perfect sense. Appreciate the very quick reply.
Regards, Peter.
-
Peter
What is this code?
Is it worksheet event code?
If so does it apply to every worksheet?
If it does you might want to look at putting the code in the ThisWorkbook module.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules