+ Reply to Thread
Results 1 to 9 of 9

Very slow ClearContents or Delete for large range

  1. #1
    Registered User
    Join Date
    08-01-2008
    Location
    Virginia
    Posts
    3

    Very slow ClearContents or Delete for large range

    I wrote a small VBA program on my laptop, a Monte Carlo simulation that ran in about 10 minutes. When I then ran it on my desktop, it appeared to not be executing, but "came to life" after about 10 minutes and executed. I tracked the difference to execution of a delete command that cleared the contents of a large range of cells.

    Please Login or Register  to view this content.
    However, it isn't a VBA issue. When I manually select the range, and press the Delete Key, it takes about 10 minutes to clear the contents of the range, with just the hourglass cursor indicating activity. Tried the following changes, with no improvement in manual times:
    - changed to manual calculation
    - removed all formulas from sheet which reference range
    - removed all other sheets on workbook

    But it still takes several minutes to clear the contents (contents are all numeric values, no contents, range is 32,000 rows by 17 columns.

    If I add a new sheet, select a similar size range, and delete, it deletes nearly instantly (the same timeframe that the original command executes on the laptop).

    Excel 2003 on both machines, both on windows XP, both updated within the last week. Laptop is the older, slower machine (single core at 2.26 GHz, 1.5 GB memory), compared to the desktop (quad core at 2.4 GHz, 3 GB memory).

    Any ideas on what might be causing the slower execution on the desktop, and how to remedy?
    Last edited by VBA Noob; 08-01-2008 at 12:47 PM.

  2. #2
    Forum Contributor
    Join Date
    02-28-2006
    Posts
    690
    create a brand new empty spreadsheet, then copy the cells into it, then delete them, then tell us how long it took...

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    You don't need to 'goto' the range to clear it.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-01-2008
    Location
    Virginia
    Posts
    3
    To: Norie - thanks, that is more efficient, but the underlying problem is not VBA related...

    To: robert111
    I tried various versions of copying into a new spreadsheet and pasting.
    - If I copy the entire worksheet, the problem persist - take ~4 minutes to clear contents
    - If I copy/paste just the range, it clears in ~1 sec
    - If I use copy/paste special - values only, for the entire worksheet, ~ 1 sec
    - If I use copy/paste special - formulas, for the entire worksheet, ~1 sec

    The existance of the problem appears to be related to copying the formats, which exist only in the "header" for the range, with respect to the impact in the delete times in the new workbook. (Formatting consists of some merged cells, background colors and borders.)

    However, if I remove the formatting in the original workbook, and resave it under another name, the problem persist...; that is, in a new worksheet, it is possible to avoid the problem (whatever it is), but once it is in a workbook, it persists.

    Note that this problem only occurs one of the two computers that I've used with this spreadsheet... which adds another dimension that may be helpful in figuring out what is happening.

    Thanks for you thoughts and input...

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Why isn't it VBA related?

    I mean you are using VBA as far as I can see.

    Perhaps you should be turning off calculation and screenupdating in the code.

  6. #6
    Registered User
    Join Date
    08-01-2008
    Location
    Virginia
    Posts
    3
    The problem isn't VBA related because I found that the delay occurs even when the VBA code isn't being executed.

    That is, if I manually select the range and then hit the "delete" key, it takes several minutes to delete the contents of the range... Of course, it is equally slow when I execute the VBA code, but that is really just using a macro to replace the keystrokes.

    Thx

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    prob the vba is trying to recalculate the whole work sheet when cells deleted have you tried removing excess formats?
    http://support.microsoft.com/kb/244435

  8. #8
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Hi

    Do you have any formulas in your workbook (doesn't matter if they are not on this sheet) using INDIRECT or OFFSET? Particularly any dynamic named ranges?

    Richard

  9. #9
    Registered User
    Join Date
    07-15-2014
    Location
    Brasil
    MS-Off Ver
    2007
    Posts
    1

    Re: Very slow ClearContents or Delete for large range

    I know the topic is very old, but once it haven't a solution...

    I changed the clear contents to a copy empty cell wiht destination to the range I want to clear.
    Its instantaneous.
    Range("AAA1").Copy Destination:= Range("A5:Z100")

+ 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