Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Don't allow Non-Unique Entry in Excel 1

Status
Not open for further replies.

JamieArvato

Technical User
Aug 5, 2004
50
0
0
GB
Don't ask ! but we keep our HR database as a single table in an Excel file....I know !!??!?

How can I ensure that each employee number that is keyed has not been used before ? I was thinking on using Worksheet_Change and then looping through every row between the one I'm on and the top and checking and if it finds an = then Application.Undo and MsgBox but don't know exactly how to write the code.

Thanks.
 
You could flag the entry with a conditional format formula
so that at least you would know by color of text that the number had been used.

Highlight the entire column..(I USED COL. A), then Format>Conditional formatting

and type the following under the "formula Is" condition
....NOTE: change A:A to your col ref.

=if(countif(A:A,A1),TRUE,FALSE)

...

set the format...{Red text maybe?)

click ok
 
Ooops wrong formula....:)

=if(countif(A:A,A1)>1,TRUE,FALSE)
 
Hi,

How about Data/Validation - Custom - Formula
[tt]
=COUNTIF($A:$A,A1)=1
[/tt]


Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
This does what you described. Hope it helps

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ColToCheck = 1
CurrentRow = Target.Row
For i = 1 To CurrentRow - 1
    If Cells(i, ColToCheck) = Cells(CurrentRow, ColToCheck) Then
        Duplicate = True
        Exit For
    End If
Next i
If Duplicate = True Then
    Duplicate = False
    Cells(CurrentRow, ColToCheck) = ""
End If
End Sub
 
I was just going there skip...:)

I used this....NOTE: change A:A to your col ref.

Highlight the entire column..(I USED COL. A), then from menu... Data>Validation

and select allow: "Custom"

THEN IN FORMULA: BAR...

=if(countif(A:A,A1)>1,FALSE,TRUE)

YOU CAN TYPE A CUSTOM MESSAGE TO USERS FROM THE MIDDLE TAB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top