+ Reply to Thread
Results 1 to 11 of 11

Too Many Cell Styles

  1. #1
    Registered User
    Join Date
    01-23-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    3

    Too Many Cell Styles

    We copy and paste spreadsheet data all the time in different instances of excel. We have noticed that certain files are "infected" and then we get a "too may cell styles" error and we are unable to copy and paste. What we have found is in the source document and the new document the cell styles are all identical at 20% accent. There is none of the normal formatting options available. We have tried to delete each cell style individaully, but they don't go away. How do we fix this copy and paste error?

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Too Many Cell Styles

    To get that error you'd need to have tens of thousands of unique cell styles. At my company, the worst I've seen is around 30,000 cell styles.

    I only see that occurring when the source workbooks have been generated by a reporting system.
    It seems that many of them
    a) create unique cell styles each time the report is run
    and
    b) somehow reuse the same Excel workbook template, accumulating large numbers of cell styles.

    However it happens, I run this code to clean them out.
    Note: At least where I work, I usually end up with a handful of "ghost" cell styles that appear, but cannot be selected.

    Please Login or Register  to view this content.
    When you're done, delete that module.

    OR you can put that code in your PERSONAL.XLSB file so the macro is always available.

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Too Many Cell Styles

    I see the same issue when I am given files from other people and it drives me crazy because I heavily rely on the default styles to keep my models tidy.

    I use the same script shown above.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  4. #4
    Registered User
    Join Date
    01-23-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    3

    Re: Too Many Cell Styles

    So I can get into the visual editor and set it up, but how do I run it and save it for the future? And do I do this on the source workbook or the destination?

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Too Many Cell Styles

    To put the code into a specific workbook:
    • ALT+F11…to open the Visual Basic Editor
    • Right-click on your workbook's name in the VBA - Projects window
    …Select: Insert Module
    • Copy the VBA code and paste it into that module:

    ------------------------------------------------
    To make the code available whenever Excel opens, you'd need to save it in a PERSONAL.XLSB
    Which Excel will create for you if you do this:
    • Display the Developer ribbon tab
    ...File.Excel_options...Popular tab
    ...Check: Show Developer Tab
    ...Click: OK

    • Click the Record Macro button (which should display on the Status Bar, next to "Ready")
    ...Store macro in: Personal Macro Workbook
    ...Click: OK
    (the Record Macro button will become a Stop Recording Macro button)

    • Click the Stop Recording Macro button

    • ALT+F11…to open the Visual Basic Editor
    • Right-click on PERSONAL workbook's name in the VBA - Projects window
    …Select: Insert Module
    • Copy the VBA code and paste it into that module:

    After you close Excel the PERSONAL.XLSB file will be saved in Excel's startup folder and will be available whenever you open Excel
    ------------------------------------------------

    Either way, you'd run that macro by:
    • Press F8 (to open the Macros window)
    ...Select: ResetCellStyles.....Click: Run


    Does that help?

  6. #6
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Too Many Cell Styles

    Note: If you want to save a workbook that contains macros, you need to
    • File.Save As
    • change the file type to either .XLSB or .XLSM

  7. #7
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Too Many Cell Styles

    Yeah or you can do what I did, which is have a standalone file to open.

    Open it.
    Switch back to the file you want to clean.
    Hit Ctrl+Shift+C and an input box will popup asking if you are sure you want to purge XX cell styles.

    CellStyleKiller.xlsm

    The code is about the same as above, but I have a little input box that pops up with a total number of cell styles, mostly so I can laugh.

    One time I had a file with over 20,000 cell styles. o_O

    The code:

    Please Login or Register  to view this content.
    Last edited by mikeTRON; 01-23-2015 at 05:19 PM.

  8. #8
    Registered User
    Join Date
    01-23-2015
    Location
    Colorado
    MS-Off Ver
    2010
    Posts
    3

    Re: Too Many Cell Styles

    Thank you! I have made it work successfully and appear to be back in business after 39k styles were deleted.

  9. #9
    Registered User
    Join Date
    06-14-2020
    Location
    Calgary, Alberta, Canada
    MS-Off Ver
    Office 2016, Win10-64
    Posts
    7

    Re: Too Many Cell Styles

    This helped me, thanks, MikeTron!

    Note:
    StyleCountLooper = 1
    should be
    StyleCount = 1

  10. #10
    Registered User
    Join Date
    02-08-2024
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    1

    Re: Too Many Cell Styles

    Hello, Just to inform that the codes above are not working in Excel 365

  11. #11
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Too Many Cell Styles

    Quote Originally Posted by Dragg64 View Post
    Hello, Just to inform that the codes above are not working in Excel 365
    This post was from January 2015 and not for Excel 365.

+ 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. Cell Styles Not Deleting
    By TravisBickle in forum Excel General
    Replies: 2
    Last Post: 04-15-2014, 06:09 AM
  2. Replies: 1
    Last Post: 03-08-2013, 02:05 PM
  3. How to delete cell styles?
    By meyestone in forum Excel General
    Replies: 7
    Last Post: 01-11-2012, 04:56 PM
  4. Styles in a cell
    By sriramp777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2006, 08:40 AM
  5. [SOLVED] Different Styles within a single Cell
    By Jérémie Gent in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-19-2006, 07:50 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