PDA

View Full Version : Solved: Copying coded worksheets



PJC
07-09-2006, 03:16 AM
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:banghead:

What is the quickest way to make duplicate sheets within the same workbook?

mdmackillop
07-09-2006, 03:27 AM
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

PJC
07-09-2006, 03:38 AM
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.

mdmackillop
07-09-2006, 03:41 AM
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

PJC
07-09-2006, 03:42 AM
Thanks MD,

That makes perfect sense. Appreciate the very quick reply.:thumb

Regards, Peter.

Norie
07-09-2006, 06:24 AM
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.