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

I am trying to create a number of copies of my existing sheet through a
for...next loop. Here is the code that I am trying to use.

Public Sub Copies30()

Dim I As Integer
Dim Sheetname As String

For I = 1 To 30
Sheetname = "PC " & Str(I)
ThisWorkbook.Worksheets(Sheetname).Copy after:=Worksheets(Sheetname)
Next I

End Sub

When stepping through this, I am getting a "subscript out of range error".
I can't understand why, as if I add a watch on Worksheets("PC 1"), I am able
to get a reference to the worksheet.

Is there anyone who can spot the problem?

Thanks in advance,

Greg