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
ADVERTISEMENT
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Aug 29, 2002
i just figured out that when you change sheets too often in VBA and get an "Activate Method Of Range Class Failed" or a "Select Method Of Range Class Failed" etc, simply retype the sheets command before it
for example :
Sheets("Work1").Select
Range("A1:D50").Select
OR
Sheets(Work1").Range("A1:D50").Select
this code in VBA, if used too often or the mentioned sheet is not the currently selected sheet in a Sub, will cause errors, and to correct this, simply type
Sheets("Work1").Select
Sheets("Work1").Range("A1:D50").Select
this makes sure that the sheet is selected before running any other range/sheet type commands.
View 2 Replies
View Related
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
Oct 31, 2007
I have created a spreadsheet that is 38mb and needed to size it down. I recorded the following macro to do this. This essentialy jut copies the top line of the relevant columns on each page and then copies the formulas down, calculates, and then pastes just the values of these calculations, thereby reducing the sheet to a third of its size. The macro works if I run it from the macro option on the toolbar, but when I assign it to a command button I keep getting ' select method
View 13 Replies
View Related
Dec 29, 2011
I try to copy some cells from one workbook to another but keep getting the error message "paste method o range class failed."
I tried different ways to paste, such as
range("D157").PasteSpecial Paste:=xlPasteValues
or
range("D157","D330).PasteSpecial Paste:=xlPasteValues
and got the same result.
-----------------------------------------------------------
If Dir(sourcePath & Format(voucherDate - 1, "dd/mm/yyyy") & ".xlsm") "" Then
Workbooks.Open Filename:=sourcePath & Format(voucherDate-1, "dd/mm/yyyy") & ".xlsm"
Range("H157", "H330").Copy
ActiveWorkbook.Close
Cells(157, 4).PasteSpecial Paste:=xlPasteValues
View 7 Replies
View Related
Apr 2, 2014
Code is attempting to autofilter any rows where text does not contain "0200" as indicated below, and delete all those rows. When reaching the line of code below the macro bombs and I get a "AutoFilter method of Range class failed" error message. Why that line is not being recognized.
Const strTOFIND As String = "0200"
Dim lngLastRow As Long
Dim rngToCheck As Range
'Application.ScreenUpdating = False
With Sheets("Platform")
[Code] ........
View 2 Replies
View Related
Oct 7, 2003
When the public routine ChangeColours is called from a Command button called ButtonX on SheetX it works fine. But a command button called ButtonY on SheetY cannot run it. When ButtonY is clicked, the error is at the line :
Sheets("SheetX").Cells(4,5).Select
Where it says that "Select Method of Range class failed"
Private Sub ButtonX_Click()
Call ChangeColours(0)
End Sub
Private Sub ButtonY_Click()
Call ChangeColours(0)
End Sub...............
View 9 Replies
View Related
Oct 3, 2007
I have written some code to move data from one sheet to another. Since the from sheet has formulas, I use the PasteSpecial command. I have used code like this for years, and all the sudden, this starts breaking. And, here is the fun part, I run the code and it works sometimes. I never know when it will fail. It is so random. This is killing me. I have tried to create objRange object and assign them and it works sometime and fails others. Also, I tried adding the line Worksheets("Daily Dashboard"). Range ("C72").Select before the first PasteSpecial as to select the cell first before pasting. Then I get the "Select method of range class failed".
Lastly, I tried copying the code from behind a worksheet into a new module. The code is triggered by a button on the first worksheet. Still fails.
Private Sub cmdGetData_Click()
[Result1].Value = ""
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Worksheets("Calculation Sheet").Range("A39:A62").Copy
Worksheets("Daily Dashboard").Range("C72").PasteSpecial xlPasteValues
Worksheets("Calculation Sheet").Range("C39:C62").Copy
Worksheets("Daily Dashboard").Range("E72").PasteSpecial xlPasteValues
[Result1].Value = "Complete"
Application.Calculation = xlCalculationAutomatic
Sheets("Control Panel").Select
Application.ScreenUpdating = True
End Sub
View 7 Replies
View Related
Mar 10, 2007
I'm getting "1004 select method of range class failed" on the Range statement below. This code is preceded by a number of range selection and formula-setting statements, nothing unusual.
Worksheets("summary").Select
Range("B5").Select
View 13 Replies
View Related
Oct 22, 2008
I have a macro that opens a specified woorkbook that changes every month. There are formulas which are pasted to range I1 of the new workbook to calculate the totals on this sheet. Everytime i run the code though, I get an error that says "Select method of range class failed" and Range("I1").Select is apparently the error.
View 7 Replies
View Related