Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to alternate row color based on group in Excel?

doc-color-alternately-group-1

In Excel, to color every other row may be easier for most of us, but, have you ever tried to color the rows alternately based on a column value changes – Column A as following screenshot shown, in this article, I will talk about how to alternate row color based on group in Excel.

Color the rows alternately based on value changes

Color the rows alternately with two colors based on value changes


Conditional Formatting /Color every other or nth rows / column:

Kutools for Excel’s Alternate Row / Column Shading feature can help you shade or conditional formatting every other or nth row / column quickly and conveniently.

doc alternate rows-1

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


arrow blue right bubble Color the rows alternately based on value changes


To highlight the rows alternately based on group, there is no direct way for you, so you need to create a helper column and then apply the conditional formatting function to color them. Please do as follows:

1. In cell D1, the same row of the headers, enter the number 0.

2. And in cell D2, type this formula: =IF(A2=A1,D1,D1+1) (A1, A2 are the first and second cell of the column which value changes, D1 is the cell that you entered the helper number 0), see screenshot:

doc-color-alternately-group-2

3. Then drag the fill handle over to the cells that you want to apply this formula, you will get the following screenshot:

doc-color-alternately-group-3

4. And then select the data range A2:D19 which including the helper formula column, and click Home > Conditional Formatting > New Rule, see screenshot:

doc-color-alternately-group-4

5. In the New Formatting Rule dialog box, select Use a formula to determine which cells to format under the Select a Rule Type section, and enter this formula =AND(LEN($A2)>0,MOD($D2,2)=0) (A2 is the first cell of your column which you color based on, and D2 is the first cell of the helper column you created of the selected range ) into the Format values where this formula is true text box, see screenshot:

doc-color-alternately-group-5

6. Then click Format button to go to the Format Cells dialog, and select one color you like under the Fill tab, see screenshot:

doc-color-alternately-group-6

7. Then click OK > OK to close the dialogs, and the rows have been highlighted alternately based on the specific column which value changes, see screenshot:

doc-color-alternately-group-1


arrow blue right bubble Color the rows alternately with two colors based on value changes

If you want to shade the rows with two different colors alternately based on value changes as following screenshot shown, this also can be solved in Excel with Conditional Formatting.

doc-color-alternately-group-7

1. First, you should create a new helper column and formula as above method from step 1 to step 3, you will get the following screenshot:

doc-color-alternately-group-3

2. Then select the data range A2:D19, and then click Home > Conditional Formatting > Manage Rules, see screenshot:

doc-color-alternately-group-8

3. In the Conditional Formatting Rules Manager dialog box, click New Rule button, see screenshot:

doc-color-alternately-group-9

4. In the popped out New Formatting Rule dialog, click Use a formula to determine cells to format under the Select a Rule Type, and then enter this formula =ISODD($D2) (D2 is the first cell of the helper column you created of the selected range), and then click Format button to choose the formatting you like for the odd rows of the group, see screenshot:

doc-color-alternately-group-10

5. Then click OK to exit this dialog, return to the former Conditional Formatting Rules Manager dialog box, please click New Rule button again to create another rule for the even rows of the group.

doc-color-alternately-group-11

6. In the New Formatting Rule dialog box, click Use a formula to determine cells to format under the Select a Rule Type as former, and then enter this formula =ISEVEN($D2) (D2 is the first cell of the helper column you created of the selected range), and then click Format button to choose another formatting for the even rows of the group, see screenshot:

doc-color-alternately-group-12

7. Then click OK to return the Conditional Formatting Rules Manager, and you can see the two rules are created as follows:

doc-color-alternately-group-13

8. Then click OK to close this dialog, and you can see your selected data range has been shaded with two different colors alternately based on the column value changes.

Notes:

1. After coloring the rows alternately, you can hide the helper column as you need, but you can’t delete it.

2. If there are no headers in your data range, you just enter 1 as the first number in the helper column, and then apply the helper formula as usual.


Related articles:

How to shade every other or alternate rows in Excel?

How to quickly shade alternating filtered rows in Excel?


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Eric · 1 years ago
    Hey, thanks for the help. I tried this and the coloring is off by one. Any ideas?
    • To post as a guest, your comment is unpublished.
      Zach W · 7 months ago
      When you highlight the selection don't highlight the header row.
  • To post as a guest, your comment is unpublished.
    Monte · 1 years ago
    I hate helper columns. I'd rather have a huge formula before I put in a helper column. Sometimes Macros are easier, but I'm not always allowed to use macro enabled spreadsheets. When I want to use a macro, I usually run it from my Personal.xlsb, but that doesn't really help with avoiding a helper column.
  • To post as a guest, your comment is unpublished.
    George · 1 years ago
    Thank you very much for this, it was much appreciated.
  • To post as a guest, your comment is unpublished.
    guest · 1 years ago
    just use 1-prev_value, and you get alternating 1 and 0 s
  • To post as a guest, your comment is unpublished.
    Nate · 1 years ago
    Thanks for this formula, been thinking it wasn't possible for a while. Here's a question: Can you format each group to be a different color? Or are you limited to 2 alternating colors?

    Thanks!