Troubleshooting File Bloat

Wookiee

Active Member
Joined
Nov 27, 2012
Messages
429
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
File bloat happens from time to time and I'm usually able to fix such files by manually recreating them and making sure to minimize the number of different cell formats.

I just went through that process on a workbook of mine which had bloated up to a ridiculous size of 4MB (considering it contained only 3 worksheets with probably less than 200 cells containing formulas). I copied the used range of one worksheet and pasted into a new workbook. When I saved the new file at that point, the size was around 69KB. I then revised the macro code which imports data and adds it in a new sheet each month (making sure to add code to clear the contents of all unused cells before saving)*. I should note that the file is in .xlsb format (which I've always found to have the smallest file size of any of the 2007+ formats). Alas, after I ran the code, the file went up to 2.28MB.

I was briefly thinking that it might have something to do with the fact that my macro opens an old format Excel file (.xls), copies the entire sheet then pastes it into a new sheet in my report workbook. It then does some sorting and calculating, but (with the exception of subtotals) I either clear formulas from cells or convert them to their actual values. I doubted that was the issue because I have a number of files which I use on a daily basis which copy .xls files into .xlsb (and with a much greater volume of data and formulas), but they rarely go over 600KB in size.

I usually email this report to my boss every month, but I consider it a breach of email etiquette to email files of such size. I even considered including a hyperlink to the file so he could open it himself, but since it contains my co-worker's employee information, I have it saved on my personal drive.

Does anyone care to venture a hypothesis as to why my file is bloating up faster than Violet Beauregard in Willy Wonka's Chocolate Factory?


*Below is the code I wrote to clear cell contents outside of my used range of cells:
Rich (BB code):
'Clear Contents And Formats Of Superfluous Cells And Hide Extraneous Worksheet Space
With Range(Cells(1, 14), Cells(Rows.Count, Columns.Count))
    .Clear
    .EntireColumn.Hidden = True
End With
With Range(Cells(lngLastRow + 4, 1), Cells(Rows.Count, Columns.Count))
    .Clear
    .EntireRow.Hidden = True
End With
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
has the workbook been shared, that causes data to be held to show changes etc ?
 
Upvote 0
The only sharing of this file is when I email it to my boss. :)

I made the mistake of creating a shared workbook for use by folks in my department a couple of years ago and, once I was able to retire that file, I swore I would never create a shared workbook again.
 
Upvote 0
I just ran this month's version of the above-referenced report and after running the macro, it went back up over 4MB again (and there are only about 800 cells with formulas and/or formatting in the newly-added worksheet). Highly frustrating.

Has no one any ideas, suggestions, or advice to impart?
 
Upvote 0
how about a small macro that you run which copies the book out to a non macro enabled version, after converting all the calculations to fixed values so you only send the data via email, it can't get much smaller.

As a test on a spare copy, copy / paste special values and save that and see what it arrives as
 
Upvote 0
Thanks for the suggestions, Mole! I'll give them a try. It might be tricky since I've got subtotals (not sure if I can retain the 3-levels of detail if I overwrite the SUBTOTAL formulas), but it's worth a try.
 
Upvote 0
OK, so copy paste values just the formulas and leave the subtotals alone
 
Upvote 0
Well, I was pleased to find out that I could copy/paste values for the entire worksheet and it still retained the buttons allowing the user to collapse/expand based on the desired level of detail. I did that with each sheet and saved as an .xlsx file, but the file size then increased to 5.5MB. I did not expect that.

Further scrutiny of my file has given me a new hypothesis, however. Once the data has been sorted and subtotalled and set to detail level 2, my code goes through on the visible rows and inserts some more formulas and conditional formatting. I noted that the conditional formatting was only applied to each individual cell containing a formula. I'm going to try rewriting my code so that the conditional formatting applies to the entire column (at least as far down as all the data extends) instead of just cherry-picking the applicable cells. I'll post back if I find that helps.

Example of range containing conditional formatting:
Code:
=$J$8,$J$14,$J$20,$J$25,$J$30,$J$36,$J$42,$J$49,$J$54,$J$58,$J$62,$J$67,$J$72,$J$77,$J$83,$J$87,$J$91,$J$94,$J$98,$J$101,$J$105,$J$108,$J$113,$J$115,$J$117,$J$119,$J$121,$J$123,$J$127,$J$129,$J$131,$J$133,$J$135,$J$138,$J$141:$J$142

Thanks!
 
Upvote 0
have a look at LastRow

Code:
Dim LastRow As Long

 LastRow = ActiveSheet.Range("M300").End(xlUp).Row

to allow you to apply limits

or you could use that to select from there down, and delete any wayward CF
 
Upvote 0
Yeah, you probably just have excessive formatting going into infinity in the rows & columns...

Therefore, press ctrl+end to find last cell.
Move the activecell down 1 row.
Then press Ctrl+Shift+Down. Then Shift + Space Bar to select all of the rows. Delete them.

For the columns, practically the same procedure...

Ctrl+End to find last cell.
Move the activecell to the right 1 column.
Then press Ctrl+Shift+Right. Then Ctrl + Space Bar to select all of the columns. Delete them.

Save the file and the size should be much much smaller.
 
Upvote 0

Forum statistics

Threads
1,215,254
Messages
6,123,893
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top