How to Alternate Row Color Based on Cell Value in Excel – 10 Methods

The dataset contains Products, Customers and Quantity sold.

Excel Alternate Row Color Based on Cell Value

Cell values in Column B are the base values.


Method 1 – Alternate Row Color Manually Based on the Cell Value in Excel

Steps

  • Select alternate rows by pressing CTRL.

Excel Alternate Row Color Based on Cell Value

  • Go to the Home tab.
  • Select Fill Color in Font.
  • Choose Green, Accent 6, Lighter 60%.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value


Method 2 – Using the Format as Table Option in Excel

Steps

  • Select the dataset. Here, B4:D14.
  • Go to the Home tab.
  • Select Format as Table in Styles.
  • Choose Light Green, Table Style Light 7.

Excel Alternate Row Color Based on Cell Value

  • In the Create Table dialog box, check My table has headers.
  • Click OK.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value

  • Select the whole table. Here, B4:D14.
  • Go to Table Design.
  • Select Convert to Range in Tools.

Excel Alternate Row Color Based on Cell Value

  • Click Yes in the warning box.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value


Method 3 – Creating a Table to Alternate Row Color Based on the Cell Value in Excel

Steps

  • Select B4:D14.
  • Go to the Insert tab.
  • Select Table in Tables.

Excel Alternate Row Color Based on Cell Value

  • In the Create Table dialog box, click OK.

Excel Alternate Row Color Based on Cell Value

The data range is converted into the following table with alternate row colors.

Excel Alternate Row Color Based on Cell Value

  • To convert the table into the range, follow the steps in Method 2.

Excel Alternate Row Color Based on Cell Value

Read More: How to Alternate Row Colors in Excel Without Table


Method 4 – Using the Format Painter Option

Steps

  • Select the second row in the range and go to the Home tab.
  • Select Fill Color in Font.
  • Choose Green, Accent 6, Lighter 60%.

Excel Alternate Row Color Based on Cell Value

One row has no color and  the other row has color. Use the Format Painter to copy this format.

  • Select the first two rows: 5 and 6.
  • Select Format Painter in Clipboard.
  • Drag the Format Painter sign down and to the right side.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value


Method 5 – Applying the IF and MOD Functions

Steps

  • Select E4 and enter Zero (0) into the cell.
0
  • Press ENTER.

Excel Alternate Row Color Based on Cell Value

  • Select E5 and enter the following formula.
=MOD(IF(B5=B4,E4,E4+1),2)

Formula Breakdown
IF(B5=B4, E4, E4+1): The IF function checks the value of B5 and B4. If both values match, the function returns the value of E4. Otherwise, it will add 1 to the value of E4.
MOD(IF(B5=B4, E4, E4+1),2): The MOD function divides the result of the IF function by 2 and shows the value of the remainder.

  • Press ENTER.

Excel Alternate Row Color Based on Cell Value

  • Double-click the Fill Handle icon to copy the formula to the rest of the cells.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value

  • Select B5:E14.
  • Go to the Home tab
  • Click the drop-down arrow of Conditional Formatting in Styles.
  • Select New Rule.

Excel Alternate Row Color Based on Cell Value

  • In the New Formatting Rule dialog box, select Use a formula to determine which cells to format in Select a Rule Type.
  • Enter the following formula in Format values where the formula is true.
=$E5=1
  • Click Format.

Excel Alternate Row Color Based on Cell Value

  • In the Format Cells dialog box, select Fill.
  • Choose a color. Here, Green, Accent 6, Lighter 60%.
  • Click OK.

Excel Alternate Row Color Based on Cell Value

  • Click OK to close the New Formatting Rule dialog box.

Excel Alternate Row Color Based on Cell Value

IThis is the output.

Excel Alternate Row Color Based on Cell Value

  • Right-click Column E.
  • Select Hide.

Excel Alternate Row Color Based on Cell Value

The extra column is hidden. This is the final output.

Excel Alternate Row Color Based on Cell Value


Method 6 – Combining the IF, MOD, and ROW Functions

Steps

  • Select E4 and enter Zero (0).
0
  • Press ENTER.

Excel Alternate Row Color Based on Cell Value

  • Select E5 and enter the following formula.
=MOD(IF(ROW()=2,0,IF(B5=B4,E4,E4+1)),2)

Formula Breakdown
ROW(): The ROW function returns the row number. Here, 5.
IF(B5=B4, E4, E4+1): The IF function checks the value of B5 and B4. If both values match, the function returns the value of E4. Otherwise, it will add 1 to the value of E4.
IF(ROW()=2,0,IF(B5=B4,E4, E4+1)): The IF function checks whether the row number is equal to 2. If the logic is True, the function returns 0. If the logic is False, the function returns the result of the second IF function.
MOD(IF(ROW()=2,0,IF(B5=B4,E4, E4+1)),2): The MOD function divides the result of the IF function by 2 and shows the value of the remainder.

  • Press ENTER.

Excel Alternate Row Color Based on Cell Value

  • Select B5:E14.
  • Go to the Home tab
  • Click the drop-down arrow of Conditional Formatting in Styles.
  • Select New Rules.

Excel Alternate Row Color Based on Cell Value

  • In the New Formatting Rule dialog box, select Use a formula to determine which cells to format in Select a Rule Type.
  • Enter the following formula in Format values where the formula is true.
=$E5=1
  • Click Format.

Excel Alternate Row Color Based on Cell Value

  • In Format Cells, select Fill.
  • Choose a color. Here, Green, Accent 6, Lighter 60%.
  • Click OK.

Excel Alternate Row Color Based on Cell Value

  • Click OK to close the New Formatting Rule dialog box.

Excel Alternate Row Color Based on Cell Value

Alternate row colors based on the value are displayed.

Excel Alternate Row Color Based on Cell Value

  • Follow the steps of Method 5 to hide the extra column.

Excel Alternate Row Color Based on Cell Value


Method 7 – Utilizing the AND, IF, LEN, and MOD Functions

Steps

  • Select E4 and enter Zero (0).
0
  • Press ENTER.
  • Select E5 and enter the following formula.
=IF(B5=B4,E4,E4+1)

Formula Breakdown
IF(B5=B4, E4, E4+1): The IF function checks the value of cell B5 and B4. If both values match, the function returns the value of E4. Otherwise, it will add 1 to the value of E4.

  • Press ENTER.

Excel Alternate Row Color Based on Cell Value

  • Select B5:E14.
  • Go to the Home tab
  • Click the drop-down arrow of Conditional Formatting in Styles.
  • Select New Rules.

Excel Alternate Row Color Based on Cell Value

  • In the New Formatting Rule dialog box, select Use a formula to determine which cells to format in Select a Rule Type.
  • Enter the following formula in Format values where the formula is true.
=AND(LEN($B5)>0,MOD($E5,2)=0)

Formula Breakdown
LEN($B5): The LEN function counts the length of the cell value. Here, 5.
MOD($E5,2): This function divides the value of E5 by 2 and shows the value of the remainder. Here, 1.
AND(LEN($B5)>0, MOD($E5,2)=0): In this formula, the AND function checks whether the value of the LEN function is greater than 5 and the result of the MOD function is equal to 0. If the logic is True, the row will show the selected color.

  • Click Format.

Excel Alternate Row Color Based on Cell Value

  • In Format Cells, select Fill.
  • Choose a color. Here, Green, Accent 6, Lighter 60%.
  • Click OK.

Excel Alternate Row Color Based on Cell Value

  • Click OK to close the New Formatting Rule dialog box.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value


Method 8 – Applying the ISODD Function to Alternate Row Color Based on the Cell Value in Excel

Steps

  • Select E4 and enter Zero (0).
0
  • Press ENTER.
  • Select E5 and enter the following formula.
=IF(B4=B5,E4,SUM(E4,1))

Formula Breakdown
SUM(E4,1): The SUM function adds 1 to the value of E4 and returns 1.
IF(B4=B5,E4,SUM(E4,1)): The IF function checks the value of B5 and B4. If both values match, the function returns the value of E4. If the logic is False, it returns the result of the SUM function.

  • Press ENTER.

Excel Alternate Row Color Based on Cell Value

  • Select B5:E14.
  • Go to the Home tab
  • Click the drop-down arrow of Conditional Formatting in Styles.
  • Select New Rules.

Excel Alternate Row Color Based on Cell Value

  • In the New Formatting Rule dialog box, select Use a formula to determine which cells to format in Select a Rule Type.
  • Enter the following formula in Format values where the formula is true.
=ISODD($E5)

ISODD will determine if the corresponding cell value is odd. If it is odd, it will return TRUE. If the logic is TRUE the row will show the selected color.

  • Click Format.

Excel Alternate Row Color Based on Cell Value

  • In Format Cells, select Fill.
  • Choose a color. Here, Green, Accent 6, Lighter 60%.
  • Click OK.

Excel Alternate Row Color Based on Cell Value

  • Click OK to close the New Formatting Rule dialog box.

Excel Alternate Row Color Based on Cell Value

This is the output.

Excel Alternate Row Color Based on Cell Value


Method 9 – Combining the ISEVEN Function with the Filter Option

Steps

  • Add a Helper column.

Linking ISEVEN Function with Filter Option

  • Select E5 and enter the following formula.
=ISEVEN(ROW())

The ROW function returns the row number. ISEVEN will determine if the corresponding row number is even. If it is even, it will return TRUE. Otherwise, FALSE.

  • Press ENTER.

Linking ISEVEN Function with Filter Option

  • Select the dataset: B4:E14.
  • Go to the Home tab.
  • Select Sort & Filter in Editing.
  • Choose Filter.

Linking ISEVEN Function with Filter Option

This is the filtered table.

Linking ISEVEN Function with Filter Option

  • Click the dropdown symbol in the Helper column.

Linking ISEVEN Function with Filter Option

  • Uncheck TRUE and click OK.

Linking ISEVEN Function with Filter Option

The rows with TRUE will be hidden.

Linking ISEVEN Function with Filter Option

  • Select the unhidden rows in the dataset.
  • Go to the Home tab.
  • Select Fill Color in Font.
  • Choose Green, Accent 6, Lighter 60%.

Linking ISEVEN Function with Filter Option

 

  • Click the dropdown symbol in the Helper column.

Linking ISEVEN Function with Filter Option

  • Select Clear Filter From “Helper”.
  • Click OK.

Linking ISEVEN Function with Filter Option

Alternate row colors are displayed.

Linking ISEVEN Function with Filter Option

  • Select the whole dataset including the header row.
  • Go to the Home tab.
  • Select Sort & Filter in Editing.
  • Uncheck Filter.

Linking ISEVEN Function with Filter Option

This is the output.

Linking ISEVEN Function with Filter Option


Method 10 – Using a VBA Code to Alternate Row Color Based on the Cell Value in Excel

Steps

  • Press ALT+F11.

Employing VBA Code

  • The Microsoft Visual Basic for Applications window will open.
  • Go to the Insert tab.
  • Select Module.

Employing VBA Code

  • Enter the code below.
Sub Alternate_Row_Color()
Dim y As Integer
For y = 1 To Selection.Rows.Count
If y Mod 2 = 0 Then
Selection.Rows(y).Interior.Color = RGB(198, 224, 180)
End If
Next
End Sub

Employing VBA Code

y is declared as Integer and the FOR loop will work for each row. The IF statement will ensure that if the row number is divisible by 2 or even, it will be colored.

  • Go back to the sheet and select the dataset.
  • Go to the Developer Tab.
  • Select Macros in Code.

Employing VBA Code

  • In the Macro wizard, select Alternate_Row_Color (created in the previous step).
  • Click Run.

Employing VBA Code

This is the output.

Employing VBA Code


Practice Section

Practice here.

Practice Section


Download Practice Workbook

Download the Excel workbook and practice.


Related Articles


<< Go Back to Highlight Row | Highlight in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Shahriar Abrar Rafid
Shahriar Abrar Rafid

Shahriar Abrar Rafid, BSc, Naval Architecture and Marine Engineering, Bangladesh University of Engineering and Technology, Bangladesh, has worked with the ExcelDemy project for more than 1 year. He has written over 100+ articles for ExcelDemy. He is a professional visual content developer adept at crafting scripts, meticulously editing Excel files, and delivering insightful video tutorials for YouTube channels. His work and learning interests vary from Microsoft Office Suites and Excel to Data Analysis, VBA, and Video recording and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo