Data validation not detecting pasted data

LFKim2018

Active Member
Joined
Mar 24, 2018
Messages
267
in the Data Validation check for duplicates (using countif(range,cell) formula) - it is detecting KEY IN entry
BUT NOT copy pasted data.
Is there a way for Data validation to capture also the copy pasted data?
many thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Mr. footoo
pardon, I can't get what you mean.
what I am saying is when I put a DATA > Data Validation on a cell for checking duplicate - it only captured the Keyed-in data - but not the copy pasted values. meaning if there is a previous data - I copy and paste it on another cell in the column - there is no duplicate error. It captured the duplicate error only when the duplicate is typed in.
I hope I made it clear..
thanks..
 
Upvote 0
yes, and Mr. vcoolio was very kind to help.
thank you..

Try this code in the worksheet module (The code assumes that the Data Validation Range is A1:F10.. Change range address as required)

Code:
Option Explicit

Private Const DV_RANGE_ADDRESS As String = "$A$1:$F$10" [B][COLOR=#008000]' <= Change this DV range as required[/COLOR][/B]

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim sLastOpration As String, sMessageAlert As String
    Dim sPaste As String, sAutoFill As String, sDragNDrop As String
    
    With Application
        If .LanguageSettings.LanguageID(msoLanguageIDInstall) = 1033 Then ' English
            sPaste = "Past": sAutoFill = "Auto Fill": sDragNDrop = "Drag and Drop"
            sMessageAlert = "Paste, Auto Fill and Drag&Drop operations are not allowed in range :  " & DV_RANGE_ADDRESS
        ElseIf .LanguageSettings.LanguageID(msoLanguageIDInstall) = 1036 Then 'French
            sPaste = "Coll": sAutoFill = "Recopie Incrémentée": sDragNDrop = "Glisser-déplacer"
            sMessageAlert = "Les operations de 'Collage', 'Recopie Incrémentée' et 'Glisser-déplacer' ne sont pas permises dans la plage :  " & DV_RANGE_ADDRESS
        End If
        
        If Not Intersect(Target, Range(DV_RANGE_ADDRESS)) Is Nothing Then
            sLastOpration = .CommandBars.FindControl(ID:=128).Control.List(1)
            If Left(sLastOpration, 4) = sPaste Or sLastOpration = sAutoFill Or sLastOpration = sDragNDrop Then
                .EnableEvents = False
                .Undo
                .EnableEvents = True
                 MsgBox sMessageAlert, vbCritical, "Data Validation."
            End If
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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