View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Karthik Bhat - Bangalore Karthik Bhat - Bangalore is offline
external usenet poster
 
Posts: 25
Default Run time error (Copy Method of Worksheet class failed)

Hi

Thanks for your help ..
The code is not trying to rename it to an existing worksheet.......
And what bothers me is that after the error has occurred I am unable to
make a copy of any sheet within the workbook manually (using Mouse and/
or the ctrl key). And the code stops at different counter numbers every
time I try to rerun the code.

Here is the code

Sub Invoice_Creator()

With Sheets("Summary")
For i = 1 To .UsedRange.Rows.Count ' 25 to 50 in all
If .Cells(i, 1) < "" Then
Country = Cells(i, 1)

' The error occures at the below statement
Sheets("Std Invoice").Copy Befo=Sheets(7)

Sheets("Std Invoice (2)").Name = Country
Sheets(Country).Select

Range("C1").FormulaR1C1 = Right(Country, 4)
Range("D1").FormulaR1C1 = "=RC[-1]*1"
Range("D1").Copy
Range("D1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Range("C1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("D1").ClearContents

Range("A75").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.ClearContents
Sheets("Invoice_Data").Select
Selection.AutoFilter Field:=25, Criteria1:=Right(Country, 4),
Operator:=xlAnd
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets(Country).Select
Range("A75").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("J48").Select
Selection.Copy
Range("A1").Select
Sheets("Summary").Select
Cells(i, 2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Else
End If
Sheets("Summary").Select
Range("A1").Select

Next i
End With

End Sub