Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel, too many Styles after importing a wkst from another file 2

Status
Not open for further replies.

rlee16

Technical User
Jan 19, 2003
44
HK
After consolidating various worksheets from different sources, I received a "Cannot add any more custom formats" dialog box. Looking at the styles (Format;Style), I see that there are literally hundreds of superfluous styles that I would like to delete. Is there a macro/VBA code out there that can automate the deletions?
 
This macro will delete all styles except Normal:

[tt]Sub DeleteUserStyles()
On Error Resume Next
With ThisWorkbook
For i = .Styles.Count To 1 Step -1
.Styles(i).Delete
Next i
End With
End Sub[/tt]

If you need to confirm deletion, extend the loop above this way:

[tt] For i = .Styles.Count To 1 Step -1
If MsgBox("Delete " & .Styles(i).Name & "?", vbYesNo, "Confirm action") = vbYes Then
.Styles(i).Delete
End If
Next i[/tt]

Style Normal can't be removed.
 
Combo,

Thanks for the code! I really appreciate it.

rlee16
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top