• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course โ€“ Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Toggle Excel Conditional Formatting On and Off

You are here: Home / Excel / Toggle Excel Conditional Formatting On and Off
Toggle Conditional Formatting on/off
January 5, 2017 by Mynda Treacy

One of the nice features of Excel Tables is the banded row formatting, which makes it easier to read and scan your data.

Unfortunately Excel Tables arenโ€™t efficient with large data sets (over 100k rows), but we can replicate the banded rows with Conditional Formatting, and we can toggle it on and off at the click of a button like this:

Excel conditional formatting on/off

Download the workbook

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

Download the Excel Workbook. Note: This is a .xlsx file please ensure your browser doesn't change the file extension on download.

Toggle Excel Conditional Formatting On/Off

First of all we need a check box or radio button form control. Youโ€™ll find the form controls on the Developer tab > Insert:

form controls

Note: if you donโ€™t see the developer tab click here for instructions on how to enable the Developer Tab.

Draw the check box form control onto your worksheet.

To edit the default text hold CTRL and left-click the form control; this will display the pull handles to adjust the size, and you can click inside the box to edit the text.

edit the default text

It is a floating object so you can move it around by left clicking and dragging while the pull handles are visible.

Set the Cell Link: Right-click > Format control

format control

Choose a cell to house the status of the check box. Mine is in cell I3:

status of the check box

When the check box is checked the cell link, cell I3, will contain TRUE, and when itโ€™s unchecked it contains FALSE. We use this in our Conditional Formatting formula.

Set Banded Rows with Conditional Formatting

To set the conditional formatting we first select the range of cells we want to apply the formatting to. In my case itโ€™s A6:G48.

Tip: I donโ€™t recommend you format the whole row/column as this will just bloat your file. Better to only format the rows and columns that contain data.

Then on the Home tab > Conditional Formatting > New Ruleโ€ฆ:

new rule

In the Edit Formatting Rule dialog box (shown below), choose โ€˜Use a formula to determine which cells to formatโ€™:

edit formatting rule

And in the formula field we use this formula:

=AND(MOD(SUBTOTAL(3,$A$5:$A5),2),$I$3=TRUE)

In English the formula reads:

Count the number of visible rows in column A (thatโ€™s the SUBTOTAL(3โ€ฆ part, where 3 is the COUNTA function for SUBTOTAL), divide the count SUBTOTAL returns by 2, and return the remainder, (thatโ€™s the MOD part), which will always evaluate to either 1 or zero AND check to see if cell I3 contains TRUE

Conditional Formatting formulas must always evaluate to either TRUE or FALSE, or a 1 or 0, which is the numeric equivalent of TRUE and FALSE. A TRUE or 1 will apply the format, and FALSE or 0 hides the format.

To summarise the formula; If the MOD(SUBTOTAL formula evaluates to 1 AND $I$3=TRUE then Excel will apply the format.

Letโ€™s look at the key components of the formula.

The SUBTOTAL function in the formula allows us to apply filters to the table and have the banding automatically adjust so that only the visible/unfiltered cells are banded. This is because SUBTOTAL can ignore hidden rows. Learn more about the SUBTOTAL function here.

We use absolute referencing to tell Excel which cells to reference as the conditional formatting moves through each row. This post explains how conditional formatting formulas work.

The MOD Function:

MOD function

MOD Syntax:

MOD syntax

We use SUBTOTAL to return the number argument for MOD, and the divisor is 2.

You can see it below where Iโ€™ve entered the MOD(SUBTOTAL part of the formula in column I:

MOD SUBTOTAL

Lastly, we check the value in cell I3 to see if the check box is checked (TRUE), or not checked (FALSE).

Tip 1: Column A must not have any blank cells, otherwise the SUBTOTAL count will be wrong. You can choose a different column for SUBTOTAL, just so long as there are no empty cells.

Tip 2: If you donโ€™t need to filter your data then you can simplify the formula to this:

=AND(MOD(ROW(),2),$I$3=TRUE)

Tip 3: if you donโ€™t want to toggle the banding on and off then you can omit the second logical test like so:

=MOD(ROW(),2)

Or to allow for filtering:

=MOD(SUBTOTAL(3,$A$5:$A5),2)

Ok, thatโ€™s the formula done, now you can click โ€˜Formatโ€™ to set the fill colour:

format fill colour

More Ideas

You can use the check box technique with other conditional formats. Simply add the AND wrapper like so:

=AND(your conditional format rule, check box cell link = TRUE)

You can also modify the MOD formula to band groups of rows like this:

group of rows

Click here to learn how.

Toggle Conditional Formatting on/off

More Excel Posts

linear regression

Excel Linear Regression

Excel linear regression is easy with the built-in tools. Use charts to plot linear regression or use the Data Analysis Toolpak.
speed up slow excel files

How to Improve Excel Performance

How to improve Excel performance and the various causes of slow Excel files so you can speed up Excel and avoid problems in future.
Securely Share Excel Files

Securely Share Excel Files

Securely share Excel files stored locally, on OneDrive or SharePoint. Prevent editing or downloading, specify who can open and edit the file.
excel check boxes

Interactive Excel Check Boxes

Excel check boxes are interactive elements you can link to formulas, charts, conditional formatting and more.
tips for working in multiple excel files

Hacks for Working in Multiple Excel Files

Awesome tips for navigating, arranging and working in multiple Excel files. Guaranteed to streamline your workflow and increase productivity.
chatgpt for excel

ChatGPT for Excel

Using ChatGPT for Excel can be hit and miss. Learn the best uses for ChatGPT to make your Excel life easier and what to avoid using it for.
excel templates

Where to Find Free Excel Templates

Where to find free Excel templates and how to create your own Excel templates. Using templates saves time and effort.
Easily Remove Password Protection from Excel Files

Easily Remove Excel Password Protection

How to remove Excel password protection when youโ€™ve forgotten the password. Works for sheets, workbooks and read only files.
Import data from a picture to Excel

Import Data from a Picture to Excel

Import data from a picture to Excel. Works with pictures from a file or the clipboard and loads it to the spreadsheet.
excel online

5 Excel Online Features Better than Desktop

5 Excel Online Features Better than Desktop including searchable data validation, track changes, single line ribbon and more.


Category: Excel
Previous Post:Excel IconsExcel Icons
Next Post:Finding a Needle in an Excel Haystack

Reader Interactions

Comments

  1. Naveed Rasheed

    November 16, 2020 at 11:40 am

    I want to print Excel specific sheet by choosing on/off sheets name e.g

    Sheet1. On.
    Sheet2. Off.
    Sheet3. On.
    Sheet4. On.

    Print ok button

    Note: All sheets will print except of sheet2.

    Reply
    • Mynda Treacy

      November 16, 2020 at 9:05 pm

      Hi Naveed, you’d need to write some VBA code to automate this. You might find this dynamic print area technique handy, although it doesn’t do exactly what you want.

      Reply
  2. Michael Rempel

    January 6, 2017 at 6:24 am

    Nice tip! Never thought of toggling conditional formatting before – simple but useful!

    Reply
    • Mynda Treacy

      January 6, 2017 at 9:21 am

      Cheers, Michael ๐Ÿ™‚

      Reply
  3. ehans

    January 6, 2017 at 6:02 am

    While the tip is cool for many applications, there is *SO* much more to tables than banded rows. I routinely use tables for tables in excess of 250,000 rows, though I don’t get crazy with formulas with tables that large, or I shove it into PowerQuery and do the heavy lifting there, then use Excel tables for analysis/filtering/printing.

    Reply
    • Mynda Treacy

      January 6, 2017 at 9:28 am

      Yeah, me too, Ed. I’m not saying don’t use tables, I love tables!.

      I’m just showing you how to toggle Conditional Formatting on and off and I happened to use the Table style banding as an example ๐Ÿ™‚

      As for Tables and performance, I’ve seen Tables run into performance issues with as few as 50k rows and also run perfectly well on 500k rows, it really depends on how many columns you have that contain formulas, what type of formulas they are and if you’re running 32-bit Excel or 64-bit Excel. Power Query is absolutely the best place for formula columns and this will allow you to use Tables with much larger data sets.

      Mynda

      Reply
  4. Don Finch

    January 6, 2017 at 12:16 am

    I was curious about the SUBTOTAL function how you prescribe option ‘3’ to “ignore hidden rows.” However, if I manually hid an odd number of rows I would see grey next to grey or white next to white in the banding. By choosing SUBTOTAL option ‘103’ in the formula then the behavior seemed to match your goal.

    Reply
    • Mynda Treacy

      January 6, 2017 at 11:22 am

      Hi Don,

      If you’re manually hiding rows then yes, 103 ignores these, whereas 3 and 103 ignore rows hidden with filters, which is what I have in my example.

      Cheers,

      Mynda

      Reply
  5. Jerry

    January 5, 2017 at 10:49 pm

    Hey Mynda! Where can I find additional background regarding table efficiency: “Unfortunately Excel Tables arenโ€™t efficient with large data sets (over 100k rows)”?

    Thanks! And HNY2U2!

    Reply
    • Mynda Treacy

      January 6, 2017 at 11:30 am

      Hi Jerry,

      I couldn’t find any articles that deal with this specifically, however in my experience if your tables contain lots of formula columns with functions like SUMPRODUCT that operate over arrays and the like, then you’re going to see performance issues. If you’re running 64-bit Excel then you’ll be able to handle bigger tables with more formulas before you see problems, whereas 32-bit Excel users will feel the pain much sooner.

      If you have a large table with no formulas and are running 64-bit then you can probably get away with tables containing 500k rows, but a 32-bit user with a table containing lots of VLOOKUP formulas might see issues with only 50k rows. Of course the number of columns will also have an effect.

      You might consider shifting the formula calculations to Power Query so the table you bring into the worksheet only contains values, i.e. no formulas.

      Mynda

      Reply
  6. Mark P

    January 5, 2017 at 10:22 pm

    I’ve used conditional formatting to apply banded rows before, but never with an on/off toggle. What a great idea. Now I’m wondering what else I can toggle on/off in a similar way.

    Reply
    • Mynda Treacy

      January 5, 2017 at 10:56 pm

      Glad you liked it, Mark. Happy formatting ๐Ÿ™‚

      Reply
  7. Deniz Aksen

    January 5, 2017 at 9:18 pm

    Dear Mynda,

    the use of the SUBTOTAL() function to count the number of VISIBLE nonblank cells from the top row through the current row in a filtered data table is a brilliant idea. To couple this SUBTOTAL() function with a simple MOD() function to distinguish between odd and even numbered rows is an even more clever trick. Thank you so much for sharing this very realistic example with your readers. Now I got another challenge for my prospective students in the spring semester.

    Just one “straightforward & trivial” simplification in your excellent conditional formatting formula:

    Since the value of the reference cell $I$3 is gonna be nothing but either TRUE or FALSE once linked to the checkbox, there is no need to check its value against “TRUE” once more inside the conditional formatting formula. That is, your conditional formatting formula would still work like a charm if you just rewrite it as follows:

    =AND(MOD(SUBTOTAL(3,$A$5:$A5),2),$I$3)

    The logical function AND() needs logical statement arguments that result in either TRUE or FALSE. If a cell value is guaranteed to be equal to either TRUE or FALSE anyway, there is no need to construct an equality check with it inside a logical function such as AND() or OR().

    Cheers and Happy New Year to Excel Lovers all over the world! – Deniz

    Reply
    • Mynda Treacy

      January 5, 2017 at 10:56 pm

      Of course, Deniz. Head slap ๐Ÿ™‚

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

launch excel macros course excel vba course

Featured Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

239 Excel Keyboard Shortcuts

Download Free PDF

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 ยท My Online Training Hub ยท All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.