View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Wesslan Wesslan is offline
external usenet poster
 
Posts: 27
Default Loops stop working and presents "1004':

Hi I have a problem with a loop that always stops after five times,
and presents "Copy method of Worksheet class failed"

The code is :

For Year = FirstYear To LastYear
Sht2 = "" & Year & " test"
Sheets(Sht2).Delete
Sht = "" & Year & " table sheet"
Sheets(Sht).Copy Befo=Sheets(2)
Sheets(Sht & " (2)").Name = Sht2

The loop fails at:

Sheets(Sht).Copy Befo=Sheets(2)


Sheet(2) is still part of the workbook while the loop breaks down.
Any suggestions as to why the loop breaks down?

Any help is greately appreciated!