7 Ways to Alternate Row Color Based on Group in Excel

This article will delve into various techniques to apply color formatting in Microsoft Excel to distinguish between groups of rows. With this formatting, the data in a spreadsheet becomes easier to understand and analyze, especially when dealing with large datasets. Regardless of your proficiency in Excel, this article provides different options to achieve the desired formatting effect. In this article, we will explore 7 different methods to alternate row color based on group in Microsoft Excel.

Alternate Row Color Based on Group


📁 Download Excel File

Download this file to better understand.


Learn to Alternate Row Color Based on Group in Excel with These 7 Methods

Our objective today is to alternate row color based on group in Excel using 7 simple methods. For that reason, we have a dataset that is a shopping list of foods. Food items in the dataset are divided into four categories: fruit, vegetables, meat, and fish. Product names, Category, and Prices are included in distinct columns for each row. It offers a precise depiction of food and analytical groupings. We will alternate row color based on different typing using several functions like AND, LEN, MOD, IF, ROW, ISEVEN, and ISODD. In some methods, we will take help from the helper column. A helper column in Excel is an additional column used to perform calculations and support data analysis, making it easier to organize and analyze data. So, let’s get right into the central part of the article.

Dataset to Alternate Row Color Based on Group

Method 1

1. Using Basic Formula

For our first method, we choose the most basic way we can do this. We will use Excel’s Conditional Formatting feature to alternate row color based on group (Fruit, Vegetable, Meat, Fish). We will not use any helper columns in this method.

To alternate row color based on group (Fruit, Vegetable, Meat, Fish) in Excel, follow these steps:

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

Selecting New Rule to Alternate Row Color Based on Group

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=$C6="Fruit"

  • Subsequently, to choose a Fill color, click Format.

Putting formula

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

Selecting Color

  • Next, press OK to apply the Change. You will see the fruit containing rows now have the color you selected.

Result of formula

  • To add more colors based on other groups, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

Selecting Manage Rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Since we have 3 other groups of food items, we duplicate 3 more rules. Now, select Each Rule, other than the original one, and hit Edit Rule.

Editing Rules

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=$C6="Vegetable"

  • Then, select a color as we did before to highlight the “Vegetable” group.

Putting New Formula

  • Repeat the process after duplicating rules in the Conditional Formatting Rules Manager window for your other groups and Press Apply.

Repeating Edit rules to apply formula

And your final output will look like this.

Method 1 Final Result

Method 2

2. Combining AND with LEN and MOD Functions

This section will look at another method in Microsoft Excel for altering row color based on groups. The technique requires building a formula that identifies which cells should be formatted using the three functions AND, LEN, and MOD. Using this method, you may easily highlight particular sets of data in your spreadsheet, making it simpler to compare and evaluate the data. We will also create a helper column using the IF function.

The input for Excel’s AND function must consist of one or more logical expressions (arguments), each of which can be either TRUE or FALSE. If all arguments are TRUE, the AND function returns TRUE, otherwise, it returns FALSE.

The LEN function gives the total number of characters, including spaces, in a text string. It is useful to count the number of characters in a cell when performing data analysis or formatting. The MOD function returns the remainder of a division operation. The number to be divided and the divisor are provided as the two arguments, and the remainder is returned as a result. The function is useful for performing operations such as alternating row or column shading. And finally, when a condition is TRUE, the Excel IF function produces one value, and when it is FALSE, it produces a different value. Its syntax is as follows: IF(logical_test, value_if_true, value_if_false). A value, a cell reference, or even another formula might be the outcome of an IF formula.

In this method, we will alternate row color according to the even and odd numbering of rows based on food types. To alternate row color based on group in Excel using the AND, LEN, and MOD functions, follow these steps:

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, we will create the Helper Column. We will put 0 in E5 beside our header. And in E6, enter this formula.

=IF(C6=C5,E5,E5+1)

Creating helper column with IF function

  • Next, press Enter and follow up by double-clicking the Fill Handle button.

Fill handle to copy formulaThus, we have our rows numbered like this.

1: Fruit

2: Vegetable

3: Meat

4: Fish

  • Now, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

New Rule to Alternate Row Color Based on Group

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=AND(LEN($C6)>0,MOD($E6,2)=0)

🔨 Formula Breakdown

👉 The first part, LEN($C6)>0, checks if the length of the contents in cell C6 is greater than zero. If it is, then the formula returns a value of TRUE, otherwise, it returns a value of FALSE.

👉 The second part, MOD($E6,2)=0, calculates the remainder after dividing the contents of cell E6 by 2. If the result is equal to zero, then the formula returns a value of TRUE, otherwise, it returns a value of FALSE.

👉 The AND function then combines the results of the two parts of the formula. If both parts of the formula return a value of TRUE, the AND function returns a value of TRUE. The resulting value of the formula is used to determine which cells should be formatted with the alternate row color. If the formula returns a value of TRUE, then the cell will be formatted; otherwise, it will not be formatted.

  • Subsequently, to choose a Fill color, click Format.

Putting AND,LEN and MOD formula

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

Selecting Color to Alternate Row Color Based on Group

  • Next, press OK to apply the Change. You will see the rows that have even numbering now have the color you selected.

Result of AND,LEN and MOD formula

  • To add color on odd-numbered rows, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

Manage Rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Now, select a Rule and hit Edit Rule.

Editing Rules to Alternate Row Color Based on Group

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=AND(LEN($C6)>0,MOD($E6,2)>0)

🔨 Formula Breakdown

👉 The first part, LEN($C6)>0, checks if the length of the contents in cell C6 is greater than zero. If it is, then the formula returns a value of TRUE; otherwise, it returns a value of FALSE.

👉 The second part, MOD($E6,2)>0, calculates the remainder after dividing the contents of cell E6 by 2. If the result is greater than zero, then the formula returns a value of TRUE; otherwise, it returns a value of FALSE.

👉 The AND function then combines the results of the two parts of the formula. If both parts of the formula return a value of TRUE, the AND function returns a value of TRUE. The resulting value of the formula is used to determine which cells should be formatted with the alternate row color. If the formula returns a value of TRUE, then the cell will be formatted; otherwise, it will not be formatted.

  • Then, select a color as we did before to highlight the odd-numbered group.

putting formula for odd number rows

  • Finally, press OK and your final output will look like this.

Method 2 Final Result

Method 3

3. Using AND with LEN and IS Functions

This method will be similar to the last one. Instead of using MOD function, we will use ISEVEN and ISODD functions. The ISEVEN function returns TRUE if a given number is even and FALSE if it is not. Just like that, the ISODD function does the same thing for odd numbers.

In this method, we will alternate row color according to the even and odd numbering of rows based on food types. To alternate row color based on group in Excel using the AND, LEN, and IS functions to make formulas, follow these steps:

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, we will create the Helper Column. We will put 0 in E5 beside our header. And in E6, enter this formula.

=IF(C6=C5,E5,E5+1)

Using IF function to Helper column

  • Next, press Enter and follow up by double-clicking the Fill Handle button.

Double-clicking Fill handle

Thus, we have our rows numbered like this.

1: Fruit

2: Vegetable

3: Meat

4: Fish

  • Now, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

New Rule to Alternate Row Color

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=AND(LEN($C6)>0,ISEVEN($E6))

🔨 Formula Breakdown

👉 The first part, LEN($C6)>0, checks if the length of the contents in cell C6 is greater than zero. If it is, then the formula returns a value of TRUE, otherwise, it returns a value of FALSE.

👉 The second part, ISEVEN($E6), checks if the value in cell E6 is even. If it is even, the condition is TRUE.

👉 The AND function then combines the results of the two parts of the formula. If both parts of the formula return a value of TRUE, the AND function returns a value of TRUE. The resulting value of the formula is used to determine which cells should be formatted with the alternate row color. If the formula returns a value of TRUE, then the cell will be formatted; otherwise, it will not be formatted.

  • Subsequently, to choose a Fill color, click Format.

AND, LEN and ISEVEN formula to Alternate Row Color Based on Group

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

selecting color

  • Next, press OK to apply the Change. You will see the rows that have even numbering now have the color you selected.

Even row colored

  • To add color on odd-numbered rows, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

manage rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Now, select a Rule and hit Edit Rule.

Duplicating rule

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=AND(LEN($C6)>0,ISODD($E6))

🔨 Formula Breakdown

👉 The first part, LEN($C6)>0, checks if the length of the contents in cell C6 is greater than zero. If it is, then the formula returns a value of TRUE; otherwise, it returns a value of FALSE.

👉 The second part, ISODD($E6), checks if the value in cell E6 is odd. If it is odd, the condition is true.

👉 The AND function then combines the results of the two parts of the formula. If both parts of the formula return a value of TRUE, the AND function returns a value of TRUE. The resulting value of the formula is used to determine which cells should be formatted with the alternate row color. If the formula returns a value of TRUE, then the cell will be formatted; otherwise, it will not be formatted.

  • Then, select a color as we did before to highlight the odd-numbered group.

AND, LEN and ISODD formula

  • Finally, press OK and your final output will look like this.

Final Output

Method 4

4. Combining MOD, IF and ROW Functions

This method will include the usage of MOD, IF and ROW functions. But we will only create the helper column with these functions. This time, the column will represent four different types of food using only 1 and 0. Then, using  Conditional Formatting feature we will highlight the types.

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, we will create the Helper Column. We will put 0 in E5 beside our header. And in E6, enter this formula.

=MOD(IF(ROW()=2,0,IF(C6=C5,E5,E5+1)),2)

🔨 Formula Breakdown

👉 The ROW() function returns the row number of the current cell. In this case, if the row number is 2, the function returns 0.

👉 The IF function checks whether the value in cell C6 is equal to the value in cell C5. If the condition is true, it returns the value in cell E5. If the condition is false, it returns the result of the expression E5 + 1.

👉 The MOD function returns the remainder of the first argument (result of the IF function) divided by the second argument. The result of the MOD function will be either 0 or 1, depending on whether the result of the IF function is even or odd.

MOD,IF and ROW formula to make helper column

  • Next, press Enter and follow up by double-clicking the Fill Handle button.

Using FIll Handle

Thus, we have our rows numbered like this.

1: Fruit & Meat
0: Vegetable & Fish

  • Now, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

creating New rule

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=$E6=1

  • Subsequently, to choose a Fill color, click Format.

selecting color

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.
  • Next, press OK to apply the Change. You will see the rows with the number 1 now have the color you selected.

1st rule reult

  • To add color on odd-numbered rows, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

managing rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Now, select a Rule and hit Edit Rule.

Editing New formula

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=$E6=0

  • Then, select a color as we did before to highlight the rows with the number 0.

putting another formula for another group

  • Finally, press OK and your final output will look like this.

Method 4 final result

Method 5

5. Integrating MOD and IF Functions

This method will be similar to the last one. We’ll exclude the ROW function and create a helper column with MOD and IF functions. And the rest is exactly like the previous method with Conditional Formatting.

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, we will create the Helper Column. We will put 0 in E5 beside our header. And in E6, enter this formula.

=MOD(IF(C6=C5,E5,E5+1),2)

🔨 Formula Breakdown

👉The IF function checks whether the value in cell C6 is equal to the value in cell C5. If the condition is true, it returns the value in cell E5. If the condition is false, it returns the result of the expression E5 + 1.

👉The MOD function returns the remainder of the first argument (result of the IF function) divided by the second argument. The result of the MOD function will be either 0 or 1, depending on whether the result of the IF function is even or odd.

MOD and IF functions to create helper column

  • Next, press Enter and follow up by double-clicking the Fill Handle button.

fill handle to copy formula to Alternate Row Color Based on Group

Thus, we have our rows numbered like this.

1: Fruit & Meat
0: Vegetable & Fish

  • Now, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

creating New rule

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type
  • Then, enter the following formula in the Edit the Rule Description box:

=$E6=1

  • Subsequently, to choose a Fill color, click Format.

putting rules to Alternate Row Color Based on Group

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

selecting color

  • Next, press OK to apply the Change. You will see the rows with the number 1 now have the color you selected.

1st rule reult

  • To add color on odd-numbered rows, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

managing rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Now, select a Rule and hit Edit Rule.

Editing New formula

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=$E6=0

  • Then, select a color as we did before to highlight the rows with the number 0.

putting another formula for another group

  • Finally, press OK and your final output will look like this.

Method 4 final result

Method 6

6. Employing ISEVEN and ISODD Functions

In this section, we will create our helper column to make a serial number for our food types using IF function. Then in the Conditional Formatting part, we will use the ISEVEN and ISODD functions to assign different colors according to even and odd numbers.

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, we will create the Helper Column. We will put 0 in E5 beside our header. And in E6, enter this formula.

=IF(C6=C5,E5,E5+1)

Creating helper column with IF function

  • Next, press Enter and follow up by double-clicking the Fill Handle button.

Fill handle to copy formula

Thus, we have our rows numbered like this.

1: Fruit
2: Vegetable
3: Meat
4: Fish

  • Now, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

New Rule to Alternate Row Color Based on Group

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=ISEVEN($E6)

  • Subsequently, to choose a fill color, click Format.

ISEVEN formula

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

selecting color

  • Next, press OK to apply the change. You will see the rows that have even numbering now have the color you selected.

Result of ISEVEN formula

  • To add color on odd-numbered rows, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

Manage Rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Now, select a Rule and hit Edit Rule.

Duplicating and Editing rules

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=ISODD($E6)

  • Then, select a color as we did before to highlight the odd-numbered group.

ISODD formula

  • Finally, press OK and your final output will look like this.

Final Output

Method 7

7. Combining IS and ROW Functions

This last method will be a simplified version of the previously explained methods. If you don’t want to color your rows by groups, but simply by alternating rows, this method is for you. In this section, we will keep things simple by using only ISEVEN, ISODD and ROW functions. We will also exclude the helper column altogether. Let’s see our final method step by step.

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

Selecting New Rule to Alternate Row Color Based on Group

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=ISEVEN(ROW())

  • Subsequently, to choose a Fill color, click Format.

ISEVEN and ROW formula

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

selecting color

  • Next, press OK to apply the Change. You will see the even-numbered rows now have the color you selected.

ISEVEN and ROW formula result to Alternate Row Color Based on Group

  • To add more colors based on other groups, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

Managing New Rule to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Now, select a Rule and hit Edit Rule.

edit rules to alternate row color

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=ISODD(ROW())

  • Then, select a color as we did before to highlight the Odd-numbered rows.

ISODD and ROW formula

  • Finally, press OK and your final output will look like this.

MEthod 7 final result


How to Alternate Row Color Based on Cell Value in Excel

We will use Excel’s Conditional Formatting feature to alternate row color based on cell value. We will use “Fruit”, “Vegetable”, “Meat” and “Fish” as our cell values to highlight rows. To alternate row color based on cell value (Fruit, Vegetable, Meat, Fish) in Excel, follow these steps:

⬇️⬇️ STEPS ⬇️⬇️

  • Firstly, choose the cells or a range of cells to which the conditional formatting should be applied. We will select B6:D16 for our example.
  • Next, go to Home tab and under Styles group, click on the Conditional Formatting dropdown, then select New Rule.

Selecting New Rule to Alternate Row Color Based on Group

  • This selection will launch the New Formatting Rule dialog box. Pick Use a formula to determine which cells to format from the Select a Rule Type bar.
  • Then, enter the following formula in the Edit the Rule Description box:

=$C6="Fruit"

  • Subsequently, to choose a Fill color, click Format.

Putting formula

  • Now select the Fill tab and the color you want. Pressing OK will take you back to the New Formatting Rule.

selecting color

  • Next, press OK to apply the Change. You will see the fruit containing rows now have the color you selected.

Result to alternate row color based on group

  • To add more colors based on other groups, we will again go to Home tab and under Styles group, click on the Conditional Formatting But, this time we will select Manage Rules.

Selecting Manage Rules to Alternate Row Color Based on Group

  • In the Conditional Formatting Rules Manager, click Duplicate Rule. Since we have 3 other groups of food items, we duplicate 3 more rules. Now, select Each Rule, other than the original one, and hit Edit Rule.

Duplicating & Editing Rules

  • This will open up Edit Formatting Rule dialog box. Now, change the formula in the Edit the Rule Description box:

=$C6="Vegetable"

  • Then, select a color as we did before to highlight the “Vegetable” group.

Putting New Formula

  • Repeat the process after duplicating rules in the Conditional Formatting Rules Manager window for other groups.

new edited rules

And your final output will look like this.

ALternating row color based on cell value


📝 Takeaways from This Article

📌  Firstly, we used a basic formula to alternate row color based on group in Excel which requires the use of no function.

📌  Second, we combined AND,LEN and MOD functions to formulate a new way to alternate row color based on group in Excel.

📌  Again, we combined AND,LEN and IS functions to make another formula that was similar to the previous one.

📌  We also used the MOD, IF and ROW functions together, which were helpful in achieving our objective.

📌  Similarly, we integrated MOD and IF functions to create a helper column to alternate row color.

📌  Moreover, we used ISEVEN and ISODD functions separately to avoid helper column to alternate row color.

📌  Lastly, combining IS functions with ROW function gave us another option to alternate row color.


Conclusion

In conclusion, using color formatting to differentiate between groups of rows in Excel can greatly enhance the comprehensibility and organization of data in a spreadsheet. This article has outlined various methods to achieve this formatting effect. I hope you’ll be able to find a suitable method to alternate row color based on group in Excel from these. The step-by-step instructions provided will help you achieve your desired result with ease. If you have any questions, feel free to comment below. I will try to answer them as soon as possible. Have fun using Excel, and you can visit Excelden.com for more tutorials. Thank You.

(Visited 44 times, 1 visits today)
Hassan Shuvo

Hassan Shuvo

Hello, I am Mehedi Hassan Shuvo.I am an Engineering graduate from Bangladesh University of Engineering and Technology. I love reading Thriller books, watching Anime, and playing Cricket. I also love learning about new software. Excel is one of my favorite ones by far. My efforts will be worthwhile if I can utilize my expertise to assist anyone. If you find any faults in my writing please let me know.I will try to correct them as I am learning everyday.

We will be happy to hear your thoughts

Leave a reply

ExcelDen
Logo