Delete Conditional Formatting rules VBA

Folks,
I've looked for VBA code to delete any conditional formatting rules in a worksheet. What I've seen is a little confusing.
The reason is I have some worksheets that people can practice with that have conditional formatting. If the user wants to try again then they'd click on the "Try Again" command button and if any conditional formatting rules were part of the exercise those would be deleted.
Frank FreeseAsked:
Who is Participating?
 
Anthony BerenguelConnect With a Mentor Commented:
This should do the trick. I did some quick testing but it could use a thorough test. Let me know if you have any questions.
TryAgain.xlsm
0
 
Anthony BerenguelCommented:
Take a look at this. If you need to remove all conditional formatting from every sheet in the workbook you'll need to make some adjustments, but we can help you with that. http://mydailymicrosoft.blogspot.com/2011/04/excel-vba-remove-all-conditional.html
0
 
Anthony BerenguelCommented:
Also, if you attach a practice copy of your workbook I could implement the code for you and comment it so that you can learn from it.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Frank FreeseAuthor Commented:
Here's my file. The company has restricted the link you gave me.
TryAgain.xlsm
0
 
NorieVBA ExpertCommented:
This will remove all the conditional formatting in all sheets.
Dim ws As Worksheet

    For Each ws In ThisWorkbook.Worksheets
        ws.Cells.FormatConditions.Delete
    Next ws

Open in new window

0
 
Frank FreeseAuthor Commented:
I only need it for the worksheet conditional formatting applies to and not all sheets. Can I replace ".Worksheets" with the name of the worksheet, ".CalAutoMiles"? or .Worksheets."CalAutoMiles"?
0
 
Frank FreeseAuthor Commented:
Looks OK at this point - I'll work with it over the weekend and if I have a probleem I'll reconnect.
Thanks
0
 
Frank FreeseAuthor Commented:
Thank you kindly....
0
 
Anthony BerenguelCommented:
Sounds good.

Note: Right now it's looking through all the cells in the range of A1:G12. If you know that there will only be VBAConditionalFormatting in column G you can change the A1:G12 to G1:G12 in the code. Or you can change it as necessary.

One more thing, it's only looking for cells that have a red fill with white text. If there are other combinations it needs to look for you'll have to add them or let me know and I can help.

Have a good weekend.

ab
0
 
NorieVBA ExpertCommented:
If you want to delete the conditional formatting on a specific worksheet.
Worksheets("CalAuotMiles").Cells.FormatConditions.Delete

Open in new window

0
 
Frank FreeseAuthor Commented:
imnorie - I greatly appreciate your follow up here.
I really do!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.