Prevent duplicates using dynamic conditional formatting in excel
As a list grows, it would sometimes be convienient to highlight possible duplicate values. If you want to prevent duplicates, highlighting them saves you time and energy.
Usually conditional formatting does this job excellent but to manually expand the conditional formatting area every time you type a new row in your list is not efficient. We want this conditional formatting area to grow as your list grows.
So the tasks in this article are:
- Highlight duplicates
- Dynamic condititonal formatting
If your list contains only text values
See column A in the above picture
Conditional formatting formula: =COUNTIF($A$1:$A1, A1)-1>0
Conditional formatting area formula: =OFFSET($A$1,0,0,COUNTA($A:$A),1)
If your list contains only numeric values
See column B in the above picture
Conditional formatting formula: =COUNTIF($A$1:$A1, A1)-1>0
Conditional formatting area formula: =OFFSET($A$1,0,0,COUNT($A:$A),1)
How to apply the conditional formatting formula in excel 2007:
- Select the range (A1:A5)
- Click "Home" tab on the ribbon
- Click "Conditional formatting"
- Click "New rule..."
- Click "Use a formula to determine which cells to format"
- Click "Format values where this formula is true" window.
- Type =COUNTIF($A$1:$A1, A1)-1>0
- Click Format button
- Click "Fill" tab
- Select a color
- Click OK!
- Click OK!
How to apply the dynamic conditional formatting area formula in excel 2007:
- Select the range (A1:A5)
- Click "Home" tab on the ribbon
- Click "Conditional formatting"
- Click "Manage rules.."
- Click in the window "Apllies to:"
- Type =OFFSET($A$1,0,0,COUNTA($A:$A),1)
- Click ok!

The result!
Type a new duplicate value below (Row 10) and see how the conditional formatting area extends to the new row!
Download excel sample file for this tutorial.
prevent-duplicates-using-dynamic-conditional-formatting-in-excel.xls
(Excel 97-2003 Workbook *.xls)
Functions used in this article
OFFSET(reference,rows,cols, [height],[width])
Returns a reference to a range that is a given number of rows and columns from a given reference
COUNTIF(range,criteria)
Counts the number of cells within a range that meet the given condition
COUNTA(value1,[value2],)
Counts the number of cells in a range that are not empty
COUNT(value1;[value2])
Counts the number of cells in a range that contain numbers
Related blog posts
- Highlight duplicates using conditional formatting in excel
- Highlight the second or more duplicates in two lists using conditional formatting in excel
- Excel vba: Create dynamic conditional formatting
- Create a dynamic border to your list using excel conditional formatting
- Highlight duplicates where adjacent cell value meets criteria using conditional formatting in excel part 2








May 17th, 2009 at 9:33 pm
[...] formatting in excel Filed in Excel on May.17, 2009. Email This article to a Friend In a previous post I extended the conditional formatting area automatically when a new row is entered. This gave me an [...]