views:

628

answers:

4

I have a massive file with 10 sheets recreated from scratch, 12 sheets updated, 5 sheets loaded with raw data, and 7 sheets that are used by the macros for the report. I have recently added a new sheet and am running into the Excel "Too many different cell formats" problem.
I have read some of the google search results and they say I should simplify the formatting, but I don't even know how I got up to 4000 distinct cell formats, let alone how much I'm using which ones, so I can remove some. It is also popping up some times the file is run, but not all, until such time as it comes up, and then it happens every time it is run. Since the macro is doing so much of the work, including creating the 10 sheets from scratch, I am not sure what to do.
Does anyone know of a Macro I could run to get a listing of all the cell formats and how many cells are using them?
Does anyone know of a program they trust to help remove excess cell formats?
Thanks,
Craig

+1  A: 

SpreadsheetGear for .NET will coallesce non-unique formats which may help with your situation.

You can download the free trial here if you want to see whether it helps. Just load the workbook into the "SpreadsheetGear 2009 for Windows" application which is installed with the evaluation software and then save the workbook.

If you actually have that many unique formats, you will have to simplify. Every unique combination of font / cell color (Interior), number format, horizontal and vertical alignment, borders, indent level, and probably a few things I'm not thinking of will cause a unique entry in the table.

Another option is to switch to Excel 2007 which has the limit on unique cell formats increased from 4,000 to 64K.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson
Do Cell Size (width/height), Merged Cells, Comments affect the 4,000 limitation? I assume that your approach doesn't look at formatting of cells, but looks inside the Excel file logic and actually looks at the array of cell formats that Excel stores?
Craig
No, none of those 3 affect the limit. SpreadsheetGear is an Excel compatible spreadsheet component, so we must load the format table for compatibility with Excel.
Joe Erickson
So sad, I can't use your application because we have added several layers of DRM to our files. But it looks like a very valuable product from the web site. I will definitely look at it again if I end up at another company.
Craig
+3  A: 

"Cell formats" are complicated. Cells do not really have a "format". They have a font (which itself has a name and a size), a NumberFormat, Height, Width, Orientation, etc.

So you need to define what you mean by "format".

Below is code to get the Font Name and Size. You can substitute whatever attributes you like.

The code below assumes you have created a Worksheet named "Formats" in the workbook. After you run the macro, the Font Names and sizes will be listed in that worksheet.

Public Sub GetFormats()

Dim CurrentSheet As Integer
Dim UsedRange As Range
Dim CurrentCell As Range
Dim rw As Long

Sheets("Formats").Cells.ClearContents
rw = 1
For CurrentSheet = 1 To Sheets.Count
    Set UsedRange = Range(Sheets(CurrentSheet).Range("A1"), Sheets(CurrentSheet).Range("A1").SpecialCells(xlLastCell))
    For Each CurrentCell In UsedRange
        FontUsed = CurrentCell.Font.Name + ":" + CStr(CurrentCell.Font.Size)
        If Sheets("Formats").Cells.Find(FontUsed) Is Nothing Then
            Sheets("Formats").Cells(rw, 1).Value = FontUsed
            rw = rw + 1
        End If
    Next
Next CurrentSheet

End Sub

Mike Lewis
This is definitely the right path to go down, however, there are at least 20 different variables with font, interior, borders, text alignment, ..., but this approach could give a list of all the unique cell format conditions, and with an additional line or two give a count of cells that use that condition, plus the initial cell found with that formatting, allowing one to try clean up the cells. The one limitation is that we mere mortals aren't given a list of the exact format conditions that are constricted by Excel. Unless someone knows someone? Thanks, I might try and expand on this.
Craig
A: 

No programming required solution?

Your statement of the issue didn't indicate whether keeping the formats is important to you - does that mean that they are not? If not, then perhaps select all the worksheets in the workbook and then do a select all, and then bulk change the format by removing all formatting?

C!

cpkharris
The report has 9 pages that are summarized output of the operation of our factory and 10 pages that are breakdowns by process type (the ones that are created from scratch by the macro), so formatting is important. However, if I had a listing of my formatting that is rarely used, I could be convinced to get rid of some of these by changing them to some more frequently used formatting.
Craig
A: 

Lots of people seem to run into this problem. Most often the issue is related to the excessive number of unused and often corrupted styles and not so much the total count of the cell unique cell format combos. I wrote a utility to fix XL2007 OOXML files that can be saved down to XL2003. Here is the link to the blog post: http://sergeig888.spaces.live.com/blog/cns!53E1D37F76F69444!534.entry

Requres .Net3.5 and MS Excel 2007. Will fix xlsx or xlsm files. The post has a ReadMe file to go with the app.

No need to run the risk of further corrupting your file by using Open Office like it is suggested on some other forums

XLGeek
I am on Excel 2003, so no go on that. Also, I ran a style checker macro and VBA showed there were like 30 styles, with one with a corrupt name. I deleted about 10-15 of the styles.
Craig