Originally Posted by
Colin Legg
Hi,
Let's start with this:
=COUNTIF(B:B,B6)
The COUNTIF() worksheet function counts the number of cells within a range which meet a given condition. In this case, the condition is that the cells are equal to B6, so this formula counts how many times the value in B6 occurs in the range B:B. If the value in B6 is unique - that is, it only occurs once, then the formula will return 1. If it occurs twice, then the formula will return 2, and so on.
Now, we want to identify any duplicate values. Since B6 is within the range B:B, we know that the formula will always return at least 1. If the formula returns any number other than 1 then we know that the value is duplicated, so we can modify the formula to check:
=COUNTIF(B:B,B6)=1
The = sign has two purposes in Excel formulas. It can be used at the very start of the formula, and this is how Excel knows that what you're typing into the cell should be considered as a formula. When you use = in the middle of a formula, it is interpreted to be an equality operator. Here are some examples:
=1=1 returns True
=2=1 returns False
So, going back to our formula:
=COUNTIF(B:B,B6)=1
This formula says: count how many times the value B6 occurs in the range B:B; if it only occurs once then return TRUE, but if it occurs more than once then return FALSE.
The data validation element will only allow an entry if the formula returns TRUE, so it is restricting entry to be unqiue values only.
Bookmarks