+ Reply to Thread
Results 1 to 5 of 5

VBA ClearContents

  1. #1
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    VBA ClearContents

    I was doing massive of copying/pasting just now(below code is example) on multiple sheets, before doing that, the file size is less than 200kb, but the file size is almost 100MB now. It appears that ClearContents does not reduce the file size.

    The purpose of doing that: copying format (vertical alignment, horizontal alignment, text wrap, font size, font color, etc) to many rows, each column has different format.

    Why, how to reduce the file size? I saved the file and reopened it, now the file size is almost 100MB.

    Is it because of format in so many cells? If so, I will delete those rows, instead of clearcontents.

    Thanks.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA ClearContents

    Yep I think delete rows would be ideal.... Even though you are clearing, sure the formats etc remain..
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: VBA ClearContents

    You're going through a loop nearly 100 times and copying 12 columns by nearly 20,000 rows and you're multiplying the target row by 10,000 so I'm guessing you've created around a million rows of data.

    Even if you clear the contents, Excel will still consider those rows to have data.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Contributor
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    680

    Re: VBA ClearContents

    Quote Originally Posted by sintek View Post
    Yep I think delete rows would be ideal.... Even though you are clearing, sure the formats etc remain..
    Thanks, I did not know that it takes so much space, and it seems I cannot copy format to many rows.

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA ClearContents

    cannot copy format to many rows.
    You can, however, ideally only when you pass information to the rows...No need to paste endless formats unnecessary.

+ 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. [SOLVED] VBA to clearcontents through a variable
    By TG58 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-12-2015, 04:27 PM
  2. [SOLVED] ClearContents with IF statement
    By cbrd in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-28-2012, 09:52 AM
  3. [SOLVED] VBA .ClearContents code
    By SHELTONUNDERDOG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2012, 09:13 PM
  4. ClearContents
    By GeneralShamu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2011, 09:28 AM
  5. ClearContents
    By tqm1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2007, 08:47 AM
  6. [SOLVED] clearcontents for some columns of a row
    By Scott in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2006, 01:00 PM
  7. question about ClearContents
    By Mattew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2005, 12:05 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