+ Reply to Thread
Results 1 to 7 of 7

How do I speed up VBA code that clears cells

  1. #1
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    How do I speed up VBA code that clears cells

    I have a worksheet that has a number of cells that need to be cleared. When I use the F8 key on the keyboard to walk through the VBA code I noticed that it takes seconds to "Clear Contents" The cells I need to clear are not contiguious. Is there a more efficent and faster way to clear cells? Speed is very important in this code. The code is below.
    Please Login or Register  to view this content.
    Thanks in advance.
    Last edited by Bobbbo; 06-03-2017 at 07:40 PM. Reason: Mark it solved

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How do I speed up VBA code that clears cells

    Hi

    The most important thing you should do is remove all the 'Selection' stuff

    i.e. instead of
    Please Login or Register  to view this content.
    just use
    Please Login or Register  to view this content.
    It's rarely necessary to select or activate stuff. Just address any objects/ranges etc. directly.

    It would be easier to comment further if we had the workbook but if you're able to use Autofilter to filter rows 12, 15, 19:20, ...etc then you could then use a
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: How do I speed up VBA code that clears cells

    First off - don't use Select... just clear the ranges directly

    Please Login or Register  to view this content.
    ... just to start with.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How do I speed up VBA code that clears cells

    Doing the whole clear at once might be more efficient also, but definitely all those .select are redundant. Try this:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How do I speed up VBA code that clears cells

    One example
    Change this code

    Please Login or Register  to view this content.
    As
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: How do I speed up VBA code that clears cells

    Quote Originally Posted by kvsrinivasamurthy View Post
    One example
    Change this code

    Please Login or Register  to view this content.
    As
    Please Login or Register  to view this content.
    Great Idea, thanks so much!

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How do I speed up VBA code that clears cells

    If this solves the issue please remember to mark the thread as solved? Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 03-18-2022, 03:30 PM
  2. [SOLVED] VBA Code that Clears contents of specific column in row
    By Jamidd1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2016, 07:49 AM
  3. vba code to clears cells and hide rows
    By Zimmerman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2015, 10:09 AM
  4. Clear cell macro clears other cells not recorded
    By bryden2008 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2015, 02:03 PM
  5. [SOLVED] Macro for a button that clears cells adjacent to a checked checkbox
    By daveblair197 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-20-2015, 07:40 AM
  6. Macro that saves cell data to a separate spreadsheet and clears cells?
    By peepo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2010, 10:47 AM
  7. Moving section of cells clears instead!?
    By Don Wiss in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2005, 10:06 AM

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