Stop Duplicate Entries if Hand Typed or Pasted COUNTIF does nor work for Paste

daleholden

Board Regular
Joined
Sep 22, 2002
Messages
243
Hi Guys

I have a pre-filled column up to about 100 of SKU numbers. I have checked there are no duplicates currently. I have tried adding the COUNTIF function to stop duplicates but this only works for hand typed entries. I need a solution to stop duplicates hand typed or pasted in please can somebody help me?

Dale
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
A routine like this in the sheet's code module will do that, you might want to eliminate the UnDo line if you prefer that style.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim fStr As String
    With Me.Range("A:A")
        If Not Application.Intersect(Target, .Cells) Is Nothing Then
        fStr = "=Sumproduct(COUNTIF(" & .Address & "," & Application.Intersect(Target, .Cells).Address & "))"

        If Application.Intersect(Target, .Cells).Cells.Count <> Evaluate(fStr) Then
            MsgBox "Duplicate detected"
            With Application
                .EnableEvents = False
                .Undo
                .EnableEvents = True
            End With
        End If
        End If
    End With
End Sub
 
Upvote 0
Hi Mike
Bit of a newbie with VBA but i have added it to to the workbook tab but it still allows me to paste in ???

vbacode.png
 
Last edited:
Upvote 0
You put it in a normal module.

What you need to do is double click on you sheet from the list in the window on the left. That should open a widow that says something like "Workbook1 - Sheet1 (code)" at the top.

Copy paste the code into that.
 
Upvote 0
HI Mike


I have tried that but still will not work when i paste into the cell?????

I am getting 2 errors when i tab from my last entry in table to add a new entry it opens in the next free A cell i get the duplicate error (with noting in cell)

I say OK to warning box it then allows me to paste or type in duplicate!!!!


New%20ErrorSKU.png


SKUDuplicate.png
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top