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?


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
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 · 1 years 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 · 2 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!
  • To post as a guest, your comment is unpublished.
    krish · 2 years ago
    Great piece of information. you helped me to present my analysis results better.
  • To post as a guest, your comment is unpublished.
    Trisha · 2 years ago
    Thank you so much for this post, I've wanted to be able to change row color based on group for a long time.

    Easy to follow and much appreciated!
  • To post as a guest, your comment is unpublished.
    Justin · 2 years ago
    This formula (when used in conditional formatting) would alternate the row color based on group without the assistance of a helper row:

    =ISODD(SUMPRODUCT(1/COUNTIF($A$1:$A2,$A$1:$A2)))
    • To post as a guest, your comment is unpublished.
      Nate · 2 years ago
      Justin, your formula is nice because it doesn't require a helper column, but for some reason it requires extra RAM and slows the workbook down noticeably. I would recommend using the formula given in the article and just dealing with the helper column.
    • To post as a guest, your comment is unpublished.
      Dean · 2 years ago
      Hi Justin. When I use either the helper row method or yours, it formats one row off. Do you know why?
      • To post as a guest, your comment is unpublished.
        DJ · 2 years ago
        More than likely - as I did - you selected the whole columns, and not just the data (excl. any headings)