Delete ALL custom cell styles EXCEL
up vote
4
down vote
favorite
Is it possible to delete all the custom cell styles in a workbook ?
Without having to delete them all one by time.
microsoft-excel microsoft-excel-2010 vba styles
add a comment |
up vote
4
down vote
favorite
Is it possible to delete all the custom cell styles in a workbook ?
Without having to delete them all one by time.
microsoft-excel microsoft-excel-2010 vba styles
Very easy with VBA
– Gary's Student
Feb 1 at 16:53
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Is it possible to delete all the custom cell styles in a workbook ?
Without having to delete them all one by time.
microsoft-excel microsoft-excel-2010 vba styles
Is it possible to delete all the custom cell styles in a workbook ?
Without having to delete them all one by time.
microsoft-excel microsoft-excel-2010 vba styles
microsoft-excel microsoft-excel-2010 vba styles
edited Nov 23 at 14:47
asked Feb 1 at 16:46
PeterH
3,14132245
3,14132245
Very easy with VBA
– Gary's Student
Feb 1 at 16:53
add a comment |
Very easy with VBA
– Gary's Student
Feb 1 at 16:53
Very easy with VBA
– Gary's Student
Feb 1 at 16:53
Very easy with VBA
– Gary's Student
Feb 1 at 16:53
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
Try this small VBA macro:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
This resolves the Builtin vs Custom issue. Note we run the loop backwards to avoid corrupting the loop index.
add a comment |
up vote
2
down vote
Ok, this wasn't as hard to do as I first thought.
Bit messy as I don't often use vba; but this code will roll back to just the default styles:
Sub DefaultStyles()
Dim MyBook As Workbook
Dim tempBook As Workbook
Dim CurStyle As Style
Set MyBook = ActiveWorkbook
On Error Resume Next
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"
Case Else
CurStyle.Delete
End Select
Next CurStyle
Set tempBook = Workbooks.Add
Application.DisplayAlerts = False
MyBook.Styles.Merge Workbook:=tempBook
Application.DisplayAlerts = True
tempBook.Close
End Sub
Actually I like the way you loop overStyles
rather than my looping over an index.
– Gary's Student
Feb 1 at 17:07
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,j
is = 1 and then youDelete(1)
. (2) moves to (1), butj
increments to 2, so the next step isDelete(2)
, which is the old (3).For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue
– AJD
Jul 6 at 21:25
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
|
show 3 more comments
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Try this small VBA macro:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
This resolves the Builtin vs Custom issue. Note we run the loop backwards to avoid corrupting the loop index.
add a comment |
up vote
5
down vote
Try this small VBA macro:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
This resolves the Builtin vs Custom issue. Note we run the loop backwards to avoid corrupting the loop index.
add a comment |
up vote
5
down vote
up vote
5
down vote
Try this small VBA macro:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
This resolves the Builtin vs Custom issue. Note we run the loop backwards to avoid corrupting the loop index.
Try this small VBA macro:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
This resolves the Builtin vs Custom issue. Note we run the loop backwards to avoid corrupting the loop index.
edited Oct 1 at 12:54
kurast
316213
316213
answered Feb 1 at 17:00
Gary's Student
13.2k31729
13.2k31729
add a comment |
add a comment |
up vote
2
down vote
Ok, this wasn't as hard to do as I first thought.
Bit messy as I don't often use vba; but this code will roll back to just the default styles:
Sub DefaultStyles()
Dim MyBook As Workbook
Dim tempBook As Workbook
Dim CurStyle As Style
Set MyBook = ActiveWorkbook
On Error Resume Next
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"
Case Else
CurStyle.Delete
End Select
Next CurStyle
Set tempBook = Workbooks.Add
Application.DisplayAlerts = False
MyBook.Styles.Merge Workbook:=tempBook
Application.DisplayAlerts = True
tempBook.Close
End Sub
Actually I like the way you loop overStyles
rather than my looping over an index.
– Gary's Student
Feb 1 at 17:07
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,j
is = 1 and then youDelete(1)
. (2) moves to (1), butj
increments to 2, so the next step isDelete(2)
, which is the old (3).For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue
– AJD
Jul 6 at 21:25
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
|
show 3 more comments
up vote
2
down vote
Ok, this wasn't as hard to do as I first thought.
Bit messy as I don't often use vba; but this code will roll back to just the default styles:
Sub DefaultStyles()
Dim MyBook As Workbook
Dim tempBook As Workbook
Dim CurStyle As Style
Set MyBook = ActiveWorkbook
On Error Resume Next
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"
Case Else
CurStyle.Delete
End Select
Next CurStyle
Set tempBook = Workbooks.Add
Application.DisplayAlerts = False
MyBook.Styles.Merge Workbook:=tempBook
Application.DisplayAlerts = True
tempBook.Close
End Sub
Actually I like the way you loop overStyles
rather than my looping over an index.
– Gary's Student
Feb 1 at 17:07
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,j
is = 1 and then youDelete(1)
. (2) moves to (1), butj
increments to 2, so the next step isDelete(2)
, which is the old (3).For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue
– AJD
Jul 6 at 21:25
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
|
show 3 more comments
up vote
2
down vote
up vote
2
down vote
Ok, this wasn't as hard to do as I first thought.
Bit messy as I don't often use vba; but this code will roll back to just the default styles:
Sub DefaultStyles()
Dim MyBook As Workbook
Dim tempBook As Workbook
Dim CurStyle As Style
Set MyBook = ActiveWorkbook
On Error Resume Next
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"
Case Else
CurStyle.Delete
End Select
Next CurStyle
Set tempBook = Workbooks.Add
Application.DisplayAlerts = False
MyBook.Styles.Merge Workbook:=tempBook
Application.DisplayAlerts = True
tempBook.Close
End Sub
Ok, this wasn't as hard to do as I first thought.
Bit messy as I don't often use vba; but this code will roll back to just the default styles:
Sub DefaultStyles()
Dim MyBook As Workbook
Dim tempBook As Workbook
Dim CurStyle As Style
Set MyBook = ActiveWorkbook
On Error Resume Next
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"
Case Else
CurStyle.Delete
End Select
Next CurStyle
Set tempBook = Workbooks.Add
Application.DisplayAlerts = False
MyBook.Styles.Merge Workbook:=tempBook
Application.DisplayAlerts = True
tempBook.Close
End Sub
edited Jul 6 at 7:03
answered Feb 1 at 16:57
PeterH
3,14132245
3,14132245
Actually I like the way you loop overStyles
rather than my looping over an index.
– Gary's Student
Feb 1 at 17:07
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,j
is = 1 and then youDelete(1)
. (2) moves to (1), butj
increments to 2, so the next step isDelete(2)
, which is the old (3).For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue
– AJD
Jul 6 at 21:25
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
|
show 3 more comments
Actually I like the way you loop overStyles
rather than my looping over an index.
– Gary's Student
Feb 1 at 17:07
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,j
is = 1 and then youDelete(1)
. (2) moves to (1), butj
increments to 2, so the next step isDelete(2)
, which is the old (3).For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue
– AJD
Jul 6 at 21:25
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
Actually I like the way you loop over
Styles
rather than my looping over an index.– Gary's Student
Feb 1 at 17:07
Actually I like the way you loop over
Styles
rather than my looping over an index.– Gary's Student
Feb 1 at 17:07
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
Will have problems here, deleting a collection forwards.
– AJD
Jul 6 at 8:03
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@AJD Hi, thanks for your comment, what problems could be caused from this ?
– PeterH
Jul 6 at 9:16
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,
j
is = 1 and then you Delete(1)
. (2) moves to (1), but j
increments to 2, so the next step is Delete(2)
, which is the old (3). For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue– AJD
Jul 6 at 21:25
@PeterH: deleting forwards means that items in the collection are renumbered. For example, in the loop,
j
is = 1 and then you Delete(1)
. (2) moves to (1), but j
increments to 2, so the next step is Delete(2)
, which is the old (3). For Each
is an enumerating loop, so the same logic is used. There was a good explanation on StackOverflow somewhere - I can't find it, but these also explain: stackoverflow.com/questions/18858718/… , stackoverflow.com/questions/45585393/vba-loop-and-delete-issue– AJD
Jul 6 at 21:25
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
@AJD Thanks for the info, the macro itself works as intended, I have used it on several workbooks since I posted it back in Feb
– PeterH
Jul 9 at 7:09
|
show 3 more comments
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1291085%2fdelete-all-custom-cell-styles-excel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Very easy with VBA
– Gary's Student
Feb 1 at 16:53