Monday, December 01, 2008
If you have an excel file over 10mb in size excel could become unstable and it will take forever to save, backup, or pretty much do anything with. It will also use significantly more memory, degrading the performance of your machine as a whole.
I've worked in several offices dealing with excel files pushing 30mb. The reality is that these files need only be around 3 or 4mb. Regardless of how many rows of data you may be storing.
Here are my key tips to reducing the size of your excel file:
1. Remove pictures
Shadows, images, and drawings all increase file size, drawing objects created by adding 3d effects or shadows have the worst effect as they're just stored as (large) pictures. If you've added shadows to some cells, remove them.
Coloring cells also has a negative effect on file size, although more limited.
2. Delete unwanted Rows
This sounds silly, but it has a massive effect on file size.
Here's a really simple example:
I've created a workbook with 3 sheets, each with 1000 records covering 18 columns. if I write some simple text to cell 65000 in each sheet the file size jumps by 500kb.

Excel sometimes seems to extend the lower boundry of worksheets without any real reason, so if you're working with large files I suggest you check to see if there are reams of unused rows.
I've reduced the size of one particular file from 24mb to 1.5mb using only this tactic.
This also leads me on to my third point
3. Don't let macro's loop over every cell in a row / column
There are plenty of macros that will perform an assessment on every single cell in a particular column, all the way down to row 65k
Not only will this make it take about 20 minutes to run, but it can easily trick excel into thinking that it needs to save the contents of every single row (see point 2).
Here's a simple loop which will only iterate over cells if they're occupied (your data will have to be in a proper table-structure):
dim usefulCell as Range
set usefulCell = SampleSheet.Range(col1_header_range_name)
Do until usefulCell.Value = ""
'Do some stuff here, for example:
CustomerObject.Name = usefulcell.Value
CustomerObject.Address = usefulcell.offset(0, 1).Value
CustomerObject.Age = usefulcell.offset(0, 2).Value
'etc
set usefulCell = usefulCell.offset(1, 0)
Loop
4. Don't do things twice
Don't have more formulae than you have to. If you're relying on a specific calculation multiple times, only calculate it once, then refer to that calculation in subsequent cells.
Don't replicate data, there's no point copying huge wads of data from one worksheet to another, reorganize so that you only need it in one place
Use static values wherever possible: If data comes from some external source, milk that source to the max. Anything you are calculating which could be imported SHOULD be imported, calculations increase file size and reduce performance.
I hope these tips help to make your excel user experience a better one. Please email me with any questions or comments.