Thread: Copying sheets
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Greg H. Greg H. is offline
external usenet poster
 
Posts: 3
Default Copying sheets

I'm sorry Ron,

I wasn't clear in my first post, my first sheet was named "PC 1". So in this
code...

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

on the first iteration of the loop should evaluate to...

This Workbook.Worksheets("PC 1").Copy after:= Worksheets("PC 1")

Shouldn't it? The second line of the 2 line code segment is where I was
getting the error.

I apologize for taking more of your time and energy now that I have the
solution, but I always prefer the understanding so that I don't ask the same
question twice.

Thanks,
Greg



"Ron de Bruin" wrote in message
...
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