Copy Method Of Worksheet Class Fails After Running X Times

Mar 12, 2008

I am encountering a problem with worksheets.copy that occurs after the copy method is called a certain amount of times. My issue is similar (exactly the same?) to what is described in these threads:

- Worksheet Copy: Method 'Copy' of Object 'Worksheet' Failed
- Copy Method of Worksheet Class Failed in Loop Code

In my case, after running this code 40 times, it fails.

If loc_after Is Nothing Then
.COPY after:=Worksheets(sht_name_orig) 'throws error here after being called 40 times
Else
.COPY after:=loc_after
End If

I would like this code to be able to run more than 40 times. I have read Dave's suggested solution regarding creating a worksheet template:
http://www.ozgrid.com/Excel/excel-wo...-templates.htm

However, in my situation the client has specifically asked that the report come as a single stand alone excel file with no add ins. In addition, I am copying several different worksheets, not just one single template that is being used over and over.

View 7 Replies


ADVERTISEMENT

Copy Method Of Worksheet Class Failed

Dec 15, 2008

I am getting this error when I run the following VBA script.

Sub AutoShape3_Click()
Sheets("Template").Select
ActiveSheet.Copy After:=Sheets(14)
Duplicate.Hide
wksName.Show
End Sub
The break mode is highlighting
ActiveSheet.Copy After:=Sheets(14)
as the source of the error.

I've run this code many times before with no problem. The workbook has 48 worksheets in it. It's my understanding that Excel can handle many more worksheets, so that shouldn't be a problem.

View 9 Replies View Related

Copy Method Of Worksheet Class Failed ..

Nov 18, 2006

I've developed an administrative package in Excel for an After School Care programme. Essentially, there are 57 Child Records. Each record is stored on its own sheet. There are four other sheets in the workbook: three hidden templates, and the front page which holds a summary of all child attendance and balances.

Up until a short time ago, invoices were created from an "Invoices.xlt" file - the program would open the file as a new book, and copy the 1st Template page out until all invoices were created. This worked fine. I've recently changed this so the Invoice template is stored within the main workbook. After I did this, we started having problems.

We can run off up to 25-35 invoices fine (32 at this stage), but eventually it hits a point where the Activesheet.Copy command fails. After this point it is impossible to copy further sheets. I CAN, however, use Insert -> Worksheet. It is only the copy function that fails.

Because it's such a strange problem, I've uploaded an example with children's names changed. It can be found on [url]

The steps to recreate the problem are simple: Open the file, select all of the children's names (from Child to Child z), and click the "Create Invoices" button at the top.

View 4 Replies View Related

Copy Method Of Worksheet Class Failed In Loop Code

Sep 5, 2006

I have an excel sheet being used as a mini database table.Rows = records, columns = fields. I have some VBA to create a copy of base template in the workbook, then populate the new template with the data from a row/record in the db. I currently have about 100 records. After about the 57th record I recieve RT error 1004. "Copy method of worksheet class failed". I think this is becuase excel is running out of memory. My laptop has 1gig of ram, and i have closed all other apps when running the macro.

Is there a way to free up memory while the vba is running, without clearing my "for" or count position which tells the macro to create a new sheet and which row/record in the db to populate the data in the new sheet.

View 5 Replies View Related

Copy Method Of Worksheet Class Failed Error '1004'

Jan 6, 2007

I am getting the following error: Run-time Error '1004': Copy method of Worksheet class failed. after adding 53 worksheets to a workbook using VBA. I found several posts concerning this error in the forum. However, I did not find any responses that address the root cause or provide a solution.

View 3 Replies View Related

Excel 2013 :: Copy Method Of Worksheet Class Failed (Runtime Error 1004)

May 17, 2014

I'm using Excel 2013 and I'm getting an issue in vba I can't figure out. (This is something I've done several dozen time before) But everytime I try to copy a sheet in a workbook,

Sheets("Sheet1").Copy After:=WB.Sheets(WB.Sheets.Count)

I recently copied in this sheet from another workbook, and deleted all of it's formula names, but I can't copy any other sheets now either.

The Run time Error 1004: Copy method of Worksheet Class failed pops up. What is weird is that I put in a msgbox and

MsgBox (WB.Sheets.Count)

returns a "1" though the sheet has about a dozen sheets within it. I've saved the workbook and even saved it as another name.

The sheet I imported has a sheet number of 77 while the previous last sheet was 23, could this be a cause?

View 2 Replies View Related

Method 'range' Of Object 'worksheet' Fails

Apr 26, 2007

I'm trying to accomplish the following: on "LogSheet" sheet, click on the DailyCloseButton and have various lists on the "lists" sheet automatically sorted before I save and end. The code below gives an error: "Method ' Range' of object '_Worksheet' failed". I have no idea why it failed.

Private Sub DailyCloseButton_Click()
' DailyClose and sort routine

'Sort lists
Sheets("Lists").Activate

Range("Products").Select
Range("Products").Sort Key1:=Range("Products").Cells(2, 1), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal.............

View 9 Replies View Related

Range Method Fails When Moving List To Other Worksheet

Oct 1, 2008

I had this code working on a Range in a Worksheet. I decided I needed to move the range to another worksheet. I moved the data to column AA in a new sheet called Audit_Pool and renamed the sheet name in ThisWorkbook.Sheets, but I get a runtime error at the With Range statement.

With ThisWorkbook.Sheets("Audit_Pool").Range("AA:AA")
With Range(.Cells(1, 1), .Cells(.Rows.Count).End(xlUp))
Randomize
With .Cells(Int(.Rows.Count * Rnd()) + 1, 1).Resize(1, 2)
.Copy Destination:=Sheets("Audit_Results_Data_Collection").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
.Copy Destination:=Sheets("Audit_Results_Data_Collection").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
.Copy Destination:=Sheets("Audit_Results_Data_Collection").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
.Copy Destination:=Sheets("Audit_Results_Data_Collection").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)

what I missed when I moved my list to a different sheet?

View 9 Replies View Related

Sheets Copy Method Fails On Second Execution

Dec 26, 2006

When I call the following code from my Visual Basic 6 program to an excel spreadsheet, it runs great the first time, but then fails everytime after that unless I close vb6 and reopen it.

Private Sub lblGroundScheduleExcel_Click()


'return day of week
'MYHEADERDAY = Format(Now, "dddd")

'get day
''MyDay = Format(Now, "dd")
MyDay = Format(DTPicker1.Value, "dd")
'get month
''MyMonth = Format(Now, "mm")
MyMonth = Format(DTPicker1.Value, "mm")
'get year
''MyYear = Format(Now, "yyyy")
MyYear = Format(DTPicker1.Value, "yyyy")

View 3 Replies View Related

Method Of Worksheet Class Failed

Aug 29, 2007

I have a worksheet "Create Origin Zones" - sheet #17 in the array - that has 56 checkboxes.

Users can click anywhere from 1 to 56 checkboxes, and for each checkbox that is checked, I unhide a sheet "Shp Profile Tmpt", copy it after sheet #17, rename it to "Origin " + checkbox#, and give it a title based on a variable in another sheet.
Once that loop is done, I then hide the "Create Origin Zones" sheet, but the user can click a button on the new sheet to go back to the 'Create Origin Zones" sheet and add more zones by clicking more checkboxes and re-running the macro.

Problem is I get that "Run-time error '1004':Copy Method of Worksheet Class failed" when I copy too many sheets. All the solutions I saw involve saving, closing and reopening the workbook but this interrupts my loop. (It would save my workbook and close it.)

I am trying to have somewhere in my loop, say every time 20 or more checkboxes are checked, its saves, closes, reopens and continues the loop to the next checkbox and repeats the copy and paste and renaming etc.

Below is my

Sub pick_origin()

chkcounter = 0

shtnum = Sheets("Create Origin Zones").Index ' find sheet# of 'Create origin zones' to copy sheets after

For i = 1 To 56 'for the 56 origin zones checkboxes

View 4 Replies View Related

Paste Method Of Worksheet Class Failed

Aug 21, 2014

I have an application I just built last week that seemed to be working fine. It's purpose is simple. It allows the user to select multiple .rtf files from a network drive, and then it loops through them, opens them up one at a time, copies the entire contents into a "temp" sheet in the excel workbook, then copies certain data from the temp tab to the next two columns in the main "data" tab of the worksheet, deletes the temp sheet, and then repeats the process for each selected .rtf file. Finally , it does some formatting of the "data" tab. All in all, it works quite well. Or at least, it DID.

VB:
Sub CopyRTFDocToTemp()
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
With WordApp

[Code] .....

As of last night, we started getting various errors.

"Run-time error '1004': Paste Method of Worksheet class failed" error messages occasionally. The frequency seems to have increased.

We were also getting an error message that reads "Microsoft Excel is waiting for another application to complete an OLE action" error messages.

Then when I stepped through the code, I was getting an error message that read [filename I'm trying to open] "is locked for editing by" [me]. "Do you want to Open a Read Only copy, Create a local copy and merge your changes later, or Receive notification when the original copy is available"

I suspected two issues
1. The macro is not successfully opening the source file before it tries to copy it, so there is nothing to paste into Excel
2. The word file was not closed the LAST time I ran the app, so the file is getting stuck open, and I have no way to manually close it.

Finally, I rebooted the PC, and added code (activedocument.close) to close the word app after copying the contents of the rtf file

VB:

Sub CopyRTFDocToTemp()
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
With WordApp

[Code] ....

I'm considering adding a wait loop to ensure that the app has actually opened a copy of the rtf file, so it has something to copy, but I'm unsure what variable to check with that loop.

View 2 Replies View Related

Select Method Of Worksheet Class Failed

Nov 17, 2008

I have all sheets selected:

Dim ws As Worksheet
For Each ws In Sheets
If ws.Visible Then ws.Select (False)
Next

' The thing is that i now want to ungroup or select the first worksheet

Sheets(1).Select ?

And then run the same sub on all the worksheets by this:

Dim wSheet As Worksheet

For Each wSheet In Worksheets

Next wSheet

Debug error is:

Select method of worksheet class failed: Sheets(1).Select ?

View 9 Replies View Related

Paste Method Of Worksheet Class Failed - But Not On Step-thru Using F8

Jan 29, 2009

My spreadsheet has a grouped graphic that I need to repeat in a variable number of rows. I wrote a macro that copies the grouped graphic from above and pastes and positions it in the newly inserted row.

It works great when I use F8 to step thru, but if I try to actually run the macro, I get an "Paste Method of worksheet class failed." error.


Sub InsertEmployees()
Range("B18").Select
Selection.EntireRow.Copy
Selection.EntireRow.Insert Shift:=xlDown
ActiveSheet.Shapes("Group 129").Copy
Application.CutCopyMode = False
ActiveSheet.Paste
End Sub

View 9 Replies View Related

Paste Method Of Worksheet Class Failed When Macro Run Twice

Sep 30, 2006

I am working on a file which is a log of all the requests we send out to our vendors. We regularly need to re-send these requests to remind them they haven't responded yet, so I am working on a macro which takes the info from the log and re-populates the request form so everything doesn't have to be re-typed every time. I've added a MsgBox as a double-check to force people to confirm they want to re-send the request.

My problem is that if you hit "No" on the MsgBox, then try to run the code again, it gives me a Run-time Error 1004 saying "Paste method of Worksheet class failed". Can someone look at my code and see if you can tell me why it works the first time but not the second?

Sub RegenerateRequest()
If ActiveCell.Column = 1 And ActiveCell.Row > 7 Then
Application.Run "LogUnprotect"
ActiveCell.EntireRow.Copy
Sheets("Regenerate Request").Activate
Application.Run "RegenFormUnprotect"
Range("A40").Select
ActiveSheet.Paste 'this is the line the debugger highlights.............

View 3 Replies View Related

Copy Method Of Range Class Failed?

Mar 7, 2014

So below is the VBA ....

Sub quicker_Option()

Dim toDel(), i As Long
Dim RNG As Range, Cell As Long
Set RNG = Range("d2:d2500")
For Cell = 1 To RNG.Cells.Count
If Application.CountIf(RNG, RNG(Cell)) > 1 Then

[Code] .......

This is the line to debug it says

Range(toDel(i)).EntireRow.Copy ("Sheet2")

View 2 Replies View Related

Copy Method Of Range Class Failed

Jan 20, 2009

Set rngData = wksData.UsedRange

With rngData
' clear existing filter
.AutoFilter
' filter on Owner col F
.AutoFilter field:=6, Criteria1:=varOwner
' check for count > 1 since heading row should always be visible
If .Columns(1).SpecialCells(xlCellTypeVisible).count > 1 Then
.SpecialCells(xlCellTypeVisible).Copy rngOutput
End If
'clear filter
.AutoFilter
End With

Set rngOutput = wksSell.Range("A1")

It fails on the line highlighted in red, and from searches on this forum and google I think I need to specify more exactly which sheet it is. something like wksdata.SpecialCells.... but this doesn't work.

View 9 Replies View Related

Paste Method Of WorkSheet Class Failed. Error 1004

Jul 31, 2007

I am trying to filter and copy from masterlist to wholesalecertified. The data is actually pasted to WholesaleCertified, however, I got error 1004.

Sub Refresh()

With Application
.ScreenUpdating = False
.DisplayAlerts = False

Sheets("WholesaleCertified").Select
Cells.Select
Selection.ClearContents

Sheets("MasterList").Select................

View 9 Replies View Related

Run-time Error 'PasteSpecial Method Of Worksheet Class Failed'

Nov 26, 2008

I have a pretty simple macro that I recorded and attached to a button. The macro is:
Sub Paste_Data()

Cells.Select
Selection.ClearContents
ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
False
Range("A3").Select
End Sub

The user opens the file that contains this macro, then runs a report from a website that dumps into an excel file. They copy the data from the Book1 output, then click the button to paste it into the template. If done this way, it works fine.

However, if they run the report and get Book1 THEN open the file containing the macro, they get a run-time error 'PasteSpecial method of Worksheet class failed' on the 'ActiveSheet.PasteSpecial... line

View 9 Replies View Related

Copy Method Of Range Class Failed 2000

Jul 8, 2006

I encounter error 1004 and copy method of range class failed in this VB routine:

fltPreviousValue = Range(varPreviousCell).Value
fltCurrentValue = Range(varCurrentCell).Value
fltNextValue = Range(varNextCell).Value

Range(varCurrentCell).Activate

If fltCurrentValue = RangeMax(ActiveCell.Offset(-2, 0), ActiveCell.Offset(2, 0)) And _
Range(varPreviousCell).Value < Range(varCurrentCell).Value And _
Range(varCurrentCell).Value >= Range(varNextCell).Value Then
Range(varCurrentCell).Select
Selection.Copy (ActiveCell.Offset(0, 6))

I am using Excel 2000 and the error occured at the last command, the bolded one.

View 9 Replies View Related

Runtime Error 1004 Paste Method Of Worksheet Class Failed

Jun 6, 2005

Very new to VBA and having trouble with a simple macro running in 2003 that copies and pasts to another worksheet. Code as follows:

Private Sub CopyResults_Click()
'Select the filtered data and copy it
Range("A23").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("F19").Select
' Open the template and copy in the data
Workbooks.Open Filename:="C:Athens Verification DataTemplatesVerification Template.xls"
Workbooks("Verification Template.xls").Activate
ActiveSheet.Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Range("A1").Select
Application.CutCopyMode = False
End Sub

When I run CopyResults, the sheet is opened and the data copied correctly, but I get a runtime error 1004 past method of worksheet class failed, with the line 'ActiveSheet.Paste' highlighted. Don't get this when I run the same macro in 2000.

View 14 Replies View Related

Runtime Error 1004 - Select Method Of Worksheet Class Failed

Sep 17, 2012

I am getting this error when trying to generate the link report ....

Debug tells me that this makes reference to a sheet is not there , I have checked and it seems to be present

It is an urgent issue as it is preventing me to generate link reports...

View 9 Replies View Related

Runtime Error 1004 :: Paste Method Of Worksheet Class Failed

Apr 29, 2009

I have the following macro who now return a runtime error 1004, paste method of worksheet class failed.

I don't know how to change it to make it work.

Sub Paste_TOP()..

View 9 Replies View Related

VBA- Getting A Run Time Error 1004 Delete Method Of Worksheet Class Failed

Dec 28, 2009

i am getting a run time error 1004 Delete method of worksheet class failed,

ws.Delete


Sub Save()
Dim myName As String, myFolder As String, e
Dim fso As Object, temp As String

ThisWorkbook.Save

Set fso = CreateObject("Scripting.FileSystemObject")

myFolder = "C:UsersRecsDocumentsTestVBA & ExcelEmail_Files_Temp" & Year(Date) & "" & Format$(Date, "mmm")
For Each e In Split(myFolder, "")
temp = temp & IIf(temp = "", "", "") & e
If fso.FolderExists(temp) = False Then fso.CreateFolder (temp)

View 9 Replies View Related

Error 1004 :: Copy Method Of Range Class Failed ...

Feb 16, 2007

When I run this code I get a run time error 1004, copy method of range class failed, I have an autofilter on and it is showing 5 rows, the 5 cells in column A of sheet2 gets copied to sheet1 OK but I get the error?

What do I need to do to fix this?

View 9 Replies View Related

Excel 2010 :: Runtime Error - Copy Method Of Sheets Class Failed

Nov 15, 2013

Trying to be slick with my macro I have 2 sheets collecting data in a workbook. I am attempting to send as attachments only those 2 sheets. I am getting an error at the following space within the code. How do I get around this?

Code:
Sub Send_to_Me()

' Send_to_Me Macro
Dim objTemp As Object
Dim FileExt As String
Dim TempFileName As String
Dim FileFullPath As String
Dim FileFormat As Variant

[Code] ......

This is the line that I get with the message above. It is only 2 sheets. Excel 2010 Windows 2007

View 2 Replies View Related

Copy Worksheet Between Workbooks Fails

Jun 11, 2008

I've the following inherited macro which basically opens a CSV text file and copies the contents to another workbook + other things.

Sub GetFile()
' GetFile Macro
Dim ws As Worksheet
Sheets("Menu").Select
' Set Path and Filename and Import
PathName = Range("E4").Value
Filename = Range("E5").Value
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=PathName & Filename
' Setup Temp worksheet
TabNameTemp = "Temp"
' TabName = Range("A2").Value
TabName = "CSV File"....................

with the error: "Run-time error '1004':. Excel cannot insert the sheets into the destination workbook, because it contains fewer rows and columns than the source workbook. To move or copy the data to the destination workbook, you can selct the data, and then use the Copy and Paste commands to insert it into the sheets of another workbook." Nothing has changed in the CSV file or the Workbook with the macros.

View 2 Replies View Related

'Select Method' Failure 'error 1004 Select Method Of Range Class Failed'

Oct 28, 2008

My workbook holds a month template and sheets for each month. I work on modifications in the template ,but would then like to update all the monthly worksheets. I recorded a macro to show me how to start programming the vb sub, but get a runtime failure 'error 1004 Select method of range class failed' when trying to select the column to copy,

View 4 Replies View Related

On Time Method Fails On Network Drive

Sep 19, 2007

I am using the OnTime method to automatically send out a spreadsheet by email at a certain time. I am using Windows task scheduler to start up excel and OnTime to execute the email. I have got this to work on my local drive however I need to save the spreadsheet on a network drive. Task scheduler opens this up still, however OnTime doesn't seem to be working as I have tested it and the email doesn't get sent.

View 3 Replies View Related

Worksheet Copy: Method 'Copy' Of Object 'Worksheet' Failed

Nov 22, 2006

I have written code that allows a user to copy, via a button, a certain sheet any number of times. They can choose to copy that sheet 5 times and then 10 times, etc.

When the sheet tries to be copied for the 17th time, it fails with the following message: "Run-time error '1004':
Method 'Copy' of object '_Worksheet' failed"

Here is the code that I have. The second line is the line that is failing.

Worksheets("RoedForm").Select
Worksheets("RoedForm").Copy After:=Worksheets(iCount)

This always fails on the 17th copy regardless of how many different combinations of copy sheets the user tries. There are several sheets before the sheet that is to be copied and I have deleted several of those to see what happens and it still fails on the 17th copy. I also have 1GB of memory, so I don't believe that memory is an issue.

View 3 Replies View Related

Cells Of Object _Global Fails After Running A Sub.

Jul 28, 2006

I have a compilation of data on all employees ( named agents in here). On one sheet I will show graphs on diffrent figures for a specific agent. They choose which agent from a validation box in the cell 1,2 (range A2). When they have done that, I make a new list for the daterange and Cell 1,4 and Cell 1,6 (Range A4, Range A6) are validationboxes showing that list. The cells are empty to begin with.

When all validationboxes are filled, I do the graphs, and here comes the problem. After doing the graphs I get an errormessage on saying that "Method 'Cells' of object '_Global' failed" when it comes to the if-statement that has the Daterange-call in it. Ie: I dont get the errormessage when it DOESNT do the ShowCharts-sub, but after it has done that, I do get the errormessage.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.EnableEvents = False
Application. ScreenUpdating = False
'Cell 1,2 = Validation-box based on a list of agents
'Cell 1,4 = Startdate for the data to be picked for the graphs.
'Cell 1,6 = Enddate for the data to be picked for the graphs.
If Not (Cells(1, 2).Value = Empty And Cells(1, 4).Value = Empty And Cells(1, 6).Value = Empty) Then......................

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved