How to Apply Conditional Formatting in Excel When Row Value Plus 5 Matches Another Row
Question details
The user needs to apply conditional formatting to a row in Excel based on whether its cell values, when increased by 5, match any values in a specific reference row.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Highlighting data in a spreadsheet based on a specific mathematical condition between two rows.
- Observed behavior
- Cells in the target row are highlighted automatically when the value plus 5 exists in the reference row.
Ensure you have clearly identified the reference row and the target row you want to format, and note the starting cell references for your formula.
Use the COUNTIF Formula for Conditional Formatting
The most efficient way to solve this in Excel without scripts is to use a formula-based conditional formatting rule.
Highlight the cells in the row you want to apply the formatting to (for example, select cells B3 through Z3).
Go to the 'Home' tab on the Excel ribbon, click on 'Conditional Formatting', and select 'New Rule' from the dropdown menu.
In the New Formatting Rule dialog box, select the option 'Use a formula to determine which cells to format'.
In the formula input box, type =COUNTIF($B$2:$Z$2,B3+5)>0. Make sure to adjust the absolute range ($B$2:$Z$2) to match your actual reference row, and change B3 to the first cell of your target row.
Click the 'Format' button to choose your desired highlight color under the Fill tab. Click 'OK' on the format window, and then click 'OK' again to apply the rule to your selected cells.

Use Office Scripts (TypeScript) for Complex Matching
For automated workflows or highly complex workbooks, you can use a TypeScript snippet to loop through cells and apply fill colors when the mathematical condition is met.
Easily Apply Conditional Formatting with WPS Spreadsheet
WPS Office provides a highly compatible and user-friendly spreadsheet tool that perfectly supports advanced conditional formatting formulas, including COUNTIF rules, to help you analyze your data quickly.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your .xlsx workbook containing the data you wish to format.
- 2. Select your target range: Highlight the row where you want the conditional formatting to appear.
- 3. Apply a New Rule: Go to the Home tab, click Conditional Formatting > New Rule, and select the 'Use a formula' option.
- 4. Input the formula: Type =COUNTIF($B$2:$Z$2,B3+5)>0, choose your highlight format, and click OK to apply the highlighting automatically.

Frequently Asked Questions
Why is my conditional formatting applying to the wrong cells?
This usually happens when absolute and relative references are mixed up. Ensure your reference range uses absolute references (like $B$2:$Z$2) while the target cell uses a relative column reference (like B3) so the formula evaluates each cell individually.
Can I subtract 5 instead of adding 5 in the formula?
Yes, you can simply change the mathematical operator in the formula to =COUNTIF($B$2:$Z$2,B3-5)>0 to check if the row value minus 5 matches any cell in the reference row.
Does the COUNTIF formula work for text values?
The COUNTIF function itself works perfectly for text, but since you are performing a mathematical operation (+5) in this scenario, the formula strictly requires numeric values in the target row to evaluate without errors.




