Hi, I need to write a macro sub for preventing of entering duplicates in column M in excel.
Ex:
I enter "A - 100" in cell M5
If I enter "A - 100" in cell M7 I want to show me an error message that is duplicate.
Hi, I need to write a macro sub for preventing of entering duplicates in column M in excel.
Ex:
I enter "A - 100" in cell M5
If I enter "A - 100" in cell M7 I want to show me an error message that is duplicate.
Invalid post - ignore
Last edited by sourabhg98; 03-06-2016 at 08:42 AM.
are you sure?
The command is incomplete.
Last edited by bajramo; 03-06-2016 at 07:53 AM.
I am really sorry posted that by mistake.
Select column A.
Goto DATA >> DATA VALIDATION >> CUSTOM
Enter this formula- =CountIf($A$1:$A1,$A1)=1
You can change the error message as per your requirement.
Also this would work only for typed values. So if you copy values from other cells this wont work.
Last edited by sourabhg98; 03-06-2016 at 08:45 AM.
Try this:
![]()
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim EvalRange As Range Set EvalRange = Range("M4:M10000") If Intersect(Target, EvalRange) Is Nothing Then Exit Sub If Target.Cells.Count > 1 Then Exit Sub If Target.Value = "" Then Exit Sub If WorksheetFunction.CountIf(EvalRange, Target.Value) > 1 Then MsgBox Target.Value & " has already been used." & vbCr & "Do you want to use the same number (cancel) or enter a new one (retry)?", vbInformation, "Value Already Exist" Application.EnableEvents = False Target.Value = "" Application.EnableEvents = True End If End Sub
Sincerely,
mso3
Hi bajramo,
If your problem is solved then mark the thread solved.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks