Consulting

Results 1 to 4 of 4

Thread: Excel crashes during VBA cell copy

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Posts
    18
    Location

    Excel crashes during VBA cell copy

    Hi,

    I am using Cells.Copy to populate a sheet with data from a newly opened source sheet. This method is convenient (as opposed to Sheets.Copy), because the target project contain formulas referring to the specific target sheet.
    The source file is an Excel output from SAP/SRM system. With two identical versions of the same source file, excel will crash during cells.copy on the first version but carry out the method without crashing on the second.
    This pattern seem to be consistent with observations of the Excel service pack update SP2 = version 14.0.7015.1000. (Previous SP Version 14.0.60291000 does not crash during this process).
    The contents of both sheets are identical. One curious difference however, is that .SpecialCells(xlCellTypeLastCell) on the file crashing is AZ324 but IO324 on the file not causing the crash. There is no apparent reason for this difference. The source file can be significantly larger, however this as not influence.
    The VBA causing this crash is
    WS1.Cells.Copy
    WSasapio.Paste
    Both of which have been set as worksheets using set statement.

    Best regards
    Morten

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    what happens when you replace Cells with UsedRange in the code?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    The source file is an Excel output from SAP/SRM system.
    On my SAP system, what they call an Excel file is really a MIME wrapper around an XML file (IIRC)

    Try this:

    1. Open the SAP 'Excel' file and do a FileSaveAs with a new name and FileType=XLSX

    2. Compare the file sizes. The SAP file would typically be 10x the 'real' Excel file

    3. Try to copy the Cells from the FileSaveAs version and see.

    BTW, mancubus is right on with only copying what you really need to copy instead of millions of blank cells
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    +1 for Paul..

    and going on a diet will be fine if the files' sizes are too large:

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=83
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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