Thread: Copying sheets
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Copying sheets

Hi Greg

Sheetname = "PC " & Str(I)
ThisWorkbook.Worksheets(Sheetname).Copy after:=Worksheets(Sheetname)

You try to copy a sheet that don't exist


Worksheets("PC").Copy after:=Worksheets(Sheets.Count)
ActiveSheet.Name = "PC " & I


You see my code copy the Sheet "PC" after the last sheet in the workbook (Worksheets(Sheets.Count)
Then give it a name PC & I (the number in the loop)
And copy the sheet "PC" again and give it a name(30*)

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Greg H." wrote in message ...
Thank you,

your code executed perfectly and took care of my immediate need. Just for
my future knowledge, do you know why I was getting the subscript out of
range error? I'm still not sure where the error was in my code. I would
like to know so that I can avoid this in the future.

Thanks again,
Greg

"Ron de Bruin" wrote in message
...
Try this one Greg

Public Sub Copies30()
Dim I As Integer
Application.ScreenUpdating = False
For I = 1 To 30
Worksheets("PC").Copy after:=Worksheets(Sheets.Count)
ActiveSheet.Name = "PC " & I
Next I
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl