+ Reply to Thread
Results 1 to 7 of 7

How to Make one column to accept only unique value

  1. #1
    Registered User
    Join Date
    03-14-2005
    Posts
    8

    How to Make one column to accept only unique value

    Hi,

    How to make one column in the excel worksheet unique, so it can only accept unique value i.e. once written it should not be repeated.

    Regards,

    Tanny

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Try the following...

    1) Select your range of cells, for example A1:A100

    2) Data > Validation > Settings > Allow > Custom

    3) Enter the following formula:

    =COUNTIF($A$1:$A$100,A1)=1

    4) Click Ok

    If you'd like a custom message to appear when invalid data is entered, select the 'Error Alert' tab and fill-in the necessary fields.

    Hope this helps!

  3. #3
    Registered User
    Join Date
    03-14-2005
    Posts
    8

    Cool Thanks A million for helping me... one more Problem

    Duplicate values entered manually it is not accepting, but if I copy and paste, it is accepting. Can I disable the paste function for that column or it should not accept duplicate value while pasting also.

    Thanks A million for helping me !

    Tanny
    Last edited by Tanny; 03-15-2005 at 04:58 AM.

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Yes, unfortunately, Data Validation doesn't work if you paste data into your range. As far as disabling the paste function, I don't know whether that's possible. If so, it would likely have to be done using VBA. Hopefully, someone with VBA experience will be able to help.

    Meanwhile, you may want to look at the following link for alternatives...

    http://www.cpearson.com/excel/duplicat.htm

    While these methods won't prevent one from entering a duplicate entry, they will flag or highlight them.

    Hope this helps!

  5. #5
    Forum Contributor
    Join Date
    09-05-2004
    Location
    Melbourne
    Posts
    193
    Some code similar to this should help. Enter the VB Editor by right-clicking on the sheet tab of the relevant sheet and select 'view code'. Then paste this.

    Private Sub Worksheet_Change(ByVal Target As Range)

    On Error Goto Finish

    If Target.Column = 1 Then
    For Each cell In Selection
    If Application.WorksheetFunction.CountIf(Columns(1), cell.Value) > 1 Then
    Application.Undo
    MsgBox "You were trying to paste in duplicate entries"
    End If
    Next cell
    End If

    Finish:

    Application.EnableEvents = True

    End Sub

    These lines in the code set the column to do the duplicate check on

    If Target.Column = 1 Then
    If Application.WorksheetFunction.CountIf(Columns(1), cell.Value) > 1 Then

    1 currently represents Column A. Change the number to suit the column you want to check.

    Cheers!

  6. #6
    Registered User
    Join Date
    03-14-2005
    Posts
    8

    Smile Thanks again!

    Thanks again, it works.

    Regards,
    Tanny

  7. #7
    Registered User
    Join Date
    03-14-2005
    Posts
    8

    Question One small problem

    Hi Richard / Domenic ,

    It works fine , if i copy one cell and paste in that column it throws error... But if I copy more that one cell i.e. 2 or 3 values. it is able to paste and does not check uniqueness. Could you please provide any solution to this problem.



    Regards,

    Tanny

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1