Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Run-time error '1004' copy method of worksheet class failed

  Asked By: Magenta    Date: Feb 18    Category: MS Office    Views: 1525
  

Here is my code, and I got this error after it copies 63 times.
It needs to copy about 110 times.

It reads the value on each cell (A) "Tablename" worksheet and create a
new worksheet by copying another worksheet "Template", and name the
worksheet as the value on the cell.

Please help as I am working on one important project. Thanks a lot!!

Sub PopulateWorkSheet()
Dim totalrow, iSheet, rownum, v_col, icol As Integer
Dim mySht, mdata As Worksheet
Dim sheetname As String
Dim fnd As Range
Dim v_cell_value As Variant

totalrow = ActiveWorkbook.Worksheets("Tablename").UsedRange.R ows.Count

For iSheet = 1 To totalrow

Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
Set mySht = Worksheets(Worksheets.Count)
sheetname = ActiveWorkbook.Worksheets("Tablename").Cells(iShee t,
1).Value
mySht.Name = sheetname
mySht.Cells(1, 1).Value = sheetname
Set mdata = Worksheets("List")
Set fnd = mdata.Columns(1l).Find(sheetname, LookAt:=xlWhole)
rownum = fnd.Row
v_col = 5
icol = 1

Do While mdata.Cells(rownum, v_col).Value <> ""
v_cell_value = mdata.Cells(rownum, v_col).Value
mySht.Cells(2, icol).Value = v_cell_value
v_col = v_col + 1
icol = icol + 1
Loop

Next iSheet

End Sub


Share: 

 

1 Answer Found

 
Answer #1    Answered By: Courtney Hughes     Answered On: Feb 18

Did you Google your problem? The very first hit from Google is this Microsoft
article ...

support.microsoft.com/default.aspx%20

 




Tagged: