I have attached a workbook that shows some excel cell styles that I simply cannot delete manually or via vba.
I use the default cell styles (input, calculation etc etc) because I like to keep my models as clean and organized as possible. When there are 10 rogue/phantom cell styles I can't delete it drives me crazy.
I have a piece of code I run to clear the cell styles (as this file originally had about 65,000 cell styles!!!) but for some reason it will NOT clear the remaining.
Can anyone help?
Code used to purge non default cell styles:
Option Explicit
Sub StyleKill()
'this is designed to clean all the cell styles out of a workbook because I prefer to use the DEFAULTS and any custom styles are put above the defaults
'declare variables
Dim styT As Style
Dim intRet As Integer
Dim count As Long
Dim counter As Long
'count how many styles there are, mostly for LOLz
For Each styT In ActiveWorkbook.Styles
count = count + 1
Next styT
'ask if you want to delete all styles (but it means all NON default styles)
intRet = MsgBox("You have " & count & " styles to delete. Do you want to Delete?", vbYesNo)
If intRet = vbYes Then
On Error Resume Next ' error handling
counter = 1 ' used ONLY for the statusbar
For Each styT In ActiveWorkbook.Styles
Application.StatusBar = "Deleting cell style [" & counter & " of " & count & "]"
If Not styT.BuiltIn Then
'MsgBox styT.Name
'styT.IncludeProtection = False ' attempting to unlock the style BEFORE deleting but I am not sure it is working
styT.Delete
End If
counter = counter + 1
Next styT
End If
Application.StatusBar = False
End Sub
Bookmarks