+ Reply to Thread
Results 1 to 10 of 10

copy method of excel failed'

Hybrid View

ashish727 copy method of excel failed' 11-13-2008, 07:17 AM
rwgrietveld re: help ! -'copy method of... 11-13-2008, 07:24 AM
ashish727 here it is... Sub... 11-13-2008, 07:40 AM
ashish727 can someone help me with a... 11-13-2008, 08:20 AM
rwgrietveld re: copy method of excel... 11-13-2008, 09:07 AM
royUK Some explanation of what your... 11-13-2008, 08:31 AM
ashish727 france print soft has got all... 11-13-2008, 09:27 AM
ashish727 the code breaks at ... 11-13-2008, 09:29 AM
T-J See Microsoft support article... 11-13-2008, 10:18 AM
ashish727 thanks a lot guys! my... 11-13-2008, 01:01 PM
  1. #1
    Registered User
    Join Date
    10-31-2008
    Location
    London
    Posts
    10

    copy method of excel failed'

    I am running a vba code to add about 200 sheets...my code generates a sheet in one file and then pastes it in another file....after generating nad adding 38 sheets i get the error copy method of excel failed

    i tried clearing the clipboard and resuming the code but that didn,t work

    any clue as to what is the problem?

    Thanks!
    Ashish

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    re: help ! -'copy method of excel failed'

    Show the code ...
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Registered User
    Join Date
    10-31-2008
    Location
    London
    Posts
    10
    here it is...

    Sub depotfrance()
    
    Dim isin As String
    Dim company As String
    Dim j As Integer
    
    For j = 1 To 200
    
    Workbooks("france print soft.xls").Activate
    Worksheets("test1").Range("A1:u888").ClearContents
    
    isin = Worksheets("Raw data matched").Range("i422").Offset(j - 1, 0).Value
    company = Worksheets("Raw data matched").Range("f422").Offset(j - 1, 0).Value
    Worksheets("template").Range("b5").Value = isin
    Worksheets("template").Range("b3").Value = company
    Worksheets("template").Calculate
    numsheets = Workbooks("France2.xls").Sheets.Count
    Sheets("template").Copy After:=Workbooks("France2.xls").Sheets(numsheets)
    Workbooks("France2.xls").Sheets("template").Name = isin
    
    
    
    Workbooks("france print soft.xls").Activate
    Worksheets("accd2").Select
        
    Selection.AutoFilter Field:=2, Criteria1:=isin
    
    Columns("A:U").Select
        Selection.Copy
        Sheets("test1").Select
        
        Range("A2").Select
        ActiveSheet.Paste
        
    numsheets = Workbooks("France2.xls").Sheets.Count
    Sheets("test1").Copy After:=Workbooks("France2.xls").Sheets(numsheets)
    Workbooks("France2.xls").Sheets("test1").Name = isin & "drill"
    
    Next j
    
    End Sub

  4. #4
    Registered User
    Join Date
    10-31-2008
    Location
    London
    Posts
    10
    can someone help me with a code for clearing my clipboard...that might solve my problem

  5. #5
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    re: copy method of excel failed'

    The only thing I can come up with is that isin is not unique. What is the exact line it breaks?

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Some explanation of what your code is doing would help.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Registered User
    Join Date
    10-31-2008
    Location
    London
    Posts
    10
    france print soft has got all the data....there are a lot of companies and for each company I have to generate a 'template' sheet and a 'test1' sheet

    I am copying the stock ISIN and the stock name from 'raw matched data' file and pasting on the template sheet...I then copy the template sheet to the final 'france2' file...then I rename this sheet using the company's isin

    the france print soft file has an 'accd2' sheet which is autofiltered...i search the stock's isin here and copy the result in 'test1'...i then copy 'test1' into 'france2' and rename this sheet in france2 as isin&drill

    i am running the loop for 200 stocks but the code stops after working for 18 stocks

  8. #8
    Registered User
    Join Date
    10-31-2008
    Location
    London
    Posts
    10
    the code breaks at

    Sheets("test1").Copy After:=Workbooks("France2.xls").Sheets(numsheets)

  9. #9
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Quote Originally Posted by ashish727 View Post
    any clue as to what is the problem?
    See Microsoft support article 210684

    Copying worksheet programmatically causes run-time error 1004 in Excel


    The MS support article gives 2 workarounds:

    1. Save and close the workbook periodically in the copy sheets loop
    2. Insert a new worksheet from a template instead of copying an existing worksheet

  10. #10
    Registered User
    Join Date
    10-31-2008
    Location
    London
    Posts
    10
    thanks a lot guys!

    my 'test1' sheet had too many rows actually...instead of copying the whole sheet I just copied the used range and that worked for me...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1