Free Excel macros

Rebuild Default Styles

Removes every custom cell style in the active workbook and rebuilds Excel's default styles, which tidies up files that have collected hundreds of stray styles from copying and pasting.

This macro uses Turn Stuff Off/On, so add those two to the same module first.

VBA: Rebuild Default Styles

Sub RebuildDefaultStyles()
'This macro removes all styles in the active workbook and rebuilds the default styles by merging them from a new workbook.
Dim MyBook As Workbook, tempBook As Workbook, CurStyle As Style

    If MidSub <> vbYes Then Call TurnStuffOff
    Set MyBook = ActiveWorkbook 'Set MyBook to the active workbook.
    On Error Resume Next
 
    'Delete all non-default styles in the workbook.
    For Each CurStyle In MyBook.Styles
        Select Case CurStyle.Name
        Case "20% - Accent1", "20% - Accent2", _
             "20% - Accent3", "20% - Accent4", "20% - Accent5", "20% - Accent6", _
             "40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4", _
             "40% - Accent5", "40% - Accent6", "60% - Accent1", "60% - Accent2", _
             "60% - Accent3", "60% - Accent4", "60% - Accent5", "60% - Accent6", _
             "Accent1", "Accent2", "Accent3", "Accent4", "Accent5", "Accent6", _
             "Bad", "Calculation", "Check Cell", "Comma", "Comma [0]", "Currency", _
             "Currency [0]", "Explanatory Text", "Good", "Heading 1", "Heading 2", _
             "Heading 3", "Heading 4", "Input", "Linked Cell", "Neutral", "Normal", _
             "Note", "Output", "Percent", "Title", "Total", "Warning Text"
             'Do nothing, these are the default styles
            
        Case Else
            CurStyle.Delete
            
        End Select
    Next CurStyle
    
    Set tempBook = Workbooks.Add 'Open a new workbook.
    MyBook.Styles.Merge Workbook:=tempBook 'Merge styles from the new workbook into the existing workbook.
    tempBook.Close 'Close the new workbook.
    
    If MidSub <> vbYes Then Call TurnStuffOn
 
End Sub

New to macros? Set up your Personal Macro Workbook first, then paste this code into its module.