Curious Minds

Clear answers to science and history questions

Conditional Formatting Comparing Two Columns in Excel

· 6 min read · Science

In Excel for Microsoft 365, use a conditional-formatting formula to compare cells in two columns: select the cells to format, choose Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format, and enter a formula such as =$A2<>$B2. This highlights each selected row where the values in columns A and B differ; change the comparison and formula to highlight matches or apply formatting to only one column.

How the comparison formula works

Conditional formatting evaluates a formula separately for every cell in the selected range. In =$A2<>$B2, the dollar signs lock the column references to A and B, while the row number remains relative. As the rule is checked down the range, Excel effectively compares A2 with B2, then A3 with B3, and so on. The formula returns TRUE when values differ, which triggers the chosen format.

The comparison operator determines what the rule finds:

  • =$A2<>$B2 highlights different values.
  • =$A2=$B2 highlights equal values.
  • =$A2>$B2 highlights rows where the value in A is greater than the value in B.
  • =$A2<$B2 highlights rows where the value in A is less than the value in B.

These examples assume the data starts in row 2 and the rule applies to both columns A and B. If the first data row is row 5, use row 5 in the formula. The row number in the formula should match the top row of the selected range.

Set up a rule to highlight differences

For example, suppose column A contains a previous price and column B contains a current price, with headers in row 1. To highlight both cells in every row where the prices differ:

  1. Select the data range, such as A2:B100. Avoid including the header unless you intend to format it too.
  2. Choose Home > Conditional Formatting > New Rule.
  3. Select Use a formula to determine which cells to format.
  4. Enter =$A2<>$B2.
  5. Select Format, choose a fill, font, or border, and select OK. Select OK again to create the rule.

Because the range begins at row 2, Excel compares the two cells in row 2 first. When A2 and B2 differ, the formatting appears on both cells in that row. To format only the value in column B, select B2:B100 instead and use =$A2<>$B2. The absolute column references still compare A with B, while the format is restricted to the selected cells in B.

Choose the right rule for your data

Decide first whether you want to identify matches, differences, or a numerical relationship. The appropriate formula depends on the task, and the selected range determines where the format appears. A common audit use is comparing two versions of a list: select both columns to make discrepancies visible, or select one column if you want to mark just the newer values that need review.

Comparisons can also be made between nonadjacent columns. If the old values are in C and the new values are in F, select the cells to format and refer to those columns in the formula. For data starting in row 2, use =$C2<>$F2. The compared columns do not have to be part of the selected range, as long as the row references line up with the rows being formatted.

For a numerical threshold rather than a simple comparison, a formula can test the difference. With old values in A and new values in B beginning in row 2, =ABS($A2-$B2)>5 highlights selected rows when the absolute difference exceeds 5. This can be useful when small rounding changes are acceptable. The number 5 is only an example; choose a threshold appropriate to the units and purpose of your data.

Blanks, text, and exact matches

A basic comparison can treat two blank cells as equal, but one blank and one populated cell as different. If empty rows should not be highlighted, add a check that the first comparison cell is not blank. With data in A2:B100 and the rule applied to that same range, use =AND($A2<>"",$A2<>$B2). This skips rows where A is blank. If either column may be blank and you want to ignore a row whenever either cell is empty, use =AND($A2<>"",$B2<>"",$A2<>$B2).

Excel's ordinary text comparison in these formulas is not case-sensitive: “North” and “NORTH” count as equal. If capitalization itself matters, use the EXACT function. With values in A and B from row 2, =NOT(EXACT($A2,$B2)) highlights values that differ, including differences in letter case. EXACT also treats text and numbers as different types, so a number stored as text may be flagged even if it looks the same on screen.

Formatting does not change the underlying values. If a cell looks like 10.0 but contains 10.04, a comparison can find a difference that the displayed number format hides. Conversely, values that look different because of formatting may be equal internally. Check the formula bar, number formats, and whether imported numbers are stored as text when a result seems unexpected.

Fix common conditional-formatting problems

The most frequent issue is a mismatched starting row. If the selected range begins at row 3 but the formula starts with row 2, each format decision may compare the wrong row. Edit the rule through Home > Conditional Formatting > Manage Rules, check the Applies to range, and make the formula's relative row match the first row of that range.

Another common problem is locking the row accidentally. In =$A2<>$B2, the dollar signs before A and B keep the columns fixed, but there is no dollar sign before 2. If the formula were =$A$2<>$B$2, Excel would compare every row against row 2 instead of comparing each row with its own partner.

  • If no cells change, confirm that the formula returns TRUE for a row you expect to highlight and that the chosen format is visible.
  • If the wrong rows change, verify the first row in Applies to and remove any unintended dollar sign before the row number.
  • If results differ from what you see, check for extra spaces, hidden characters, text-versus-number values, and rounding.
  • If several rules affect the same cells, review their order and settings in Manage Rules; another rule may override or obscure the format.

Frequently Asked Questions

Can I compare two columns and highlight only the cells that do not match?
Select the cells in the column you want to format, such as B2:B100, and create a formula rule using =$A2<>$B2. The rule compares each B cell with the A cell on the same row, but formats only column B.

How do I highlight matching values in two columns?
Select the range to format and use =$A2=$B2, adjusting the row number to the first row in the selection. This highlights equal values row by row.

Can conditional formatting compare columns that are not next to each other?
Yes. Reference the two relevant columns in the formula. For example, to compare C and F from row 2 onward, use =$C2<>$F2 and apply the rule to the cells you want formatted.

Does this compare each value with every value in the other column?
No. The formulas shown compare cells on the same row: A2 with B2, A3 with B3, and so on. Finding whether each item appears anywhere in another list is a different task and needs a lookup or count-based rule.

Why are cells with the same displayed value highlighted as different?
The underlying values may differ even when number formatting rounds them to the same display, or one may be stored as text. Inspect the actual contents and formats; if appropriate, compare rounded values using a formula tailored to the required precision.

Do the steps differ on Mac or Excel for the web?
The formula logic is the same. In Excel for Mac, use the Home tab's Conditional Formatting controls to create a formula-based rule; labels and dialog layout can differ slightly. Excel for the web also supports conditional-formatting formulas, though some rule-management options may be arranged differently from the Windows desktop app.

In this article
  1. How the comparison formula works
  2. Set up a rule to highlight differences
  3. Choose the right rule for your data
  4. Blanks, text, and exact matches
  5. Fix common conditional-formatting problems
  6. Frequently Asked Questions