How to alternate row color based on group in Excel?
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.
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.
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!
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:
3. Then drag the fill handle over to the cells that you want to apply this formula, you will get the following screenshot:
4. And then select the data range A2:D19 which including the helper formula column, and click Home > Conditional Formatting > New Rule, see screenshot:
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:
6. Then click Format button to go to the Format Cells dialog, and select one color you like under the Fill tab, see screenshot:
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:
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.
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:
2. Then select the data range A2:D19, and then click Home > Conditional Formatting > Manage Rules, see screenshot:
3. In the Conditional Formatting Rules Manager dialog box, click New Rule button, see screenshot:
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:
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.
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:
7. Then click OK to return the Conditional Formatting Rules Manager, and you can see the two rules are created as follows:
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.
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.
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.
To post as a guest, your comment is unpublished.· 1 years agoI 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.· 1 years agoThank you very much for this, it was much appreciated.
To post as a guest, your comment is unpublished.· 1 years agojust use 1-prev_value, and you get alternating 1 and 0 s
To post as a guest, your comment is unpublished.· 1 years agoThanks 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?