data validation to work if input values are copied and paste

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
282
Office Version
  1. 365
Platform
  1. Windows
Sirs,

Is there a way that data validation will work even if the value that should be validated is from copy and paste values?

For example,

I have a column that is set for data validation. where there should be no duplicate values. If input manually, the data validation works.

However, if the values to be inputted came from copy and paste. The data validation doesn't work.


Many thanks and your response is really appreciated.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

I recommend you use conditional formatting to highlight the cell and hope the user gets the memo.
Short of that you're restricting the workbook either via permissions or VBA to deactivate ctrl-v.
Or if you really want to check validation and every other reasonable solution is exhausted you can code some VBA to check the value and emulate conditional formatting but it will break if you make changes to the workbook.....
 
Upvote 0
Worksheet event is used.
Validation list range =A2:A15.
Destination range( range validated)= B2:B5
Both can be changed as required.
If the value pasted to say B3 is not in validation list then B3 content is cleared else value remains. Validation is restored.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2:B5")) Is Nothing Then
Dim Rng As Range
Application.EnableEvents = False
Set Rng = Range("A2:A15")
    If WorksheetFunction.CountIf(Rng, Target) = 0 And Target <> "" Then
    MsgBox ("Pasted value is not in validation list, hence value deleted.")
    Target = ""
    End If
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=" & Rng.Address
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = "Pasted value is not in validation list, hence value deleted."
        .ShowInput = True
        .ShowError = True
    End With

Application.EnableEvents = True
End If
End Sub
How to use workheet event the code
Right click on Sheet tab --> view code
Visual Basic (VB) window opens.
Paste the code
Close the VB window.
Save the file as .xlsm
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,974
Members
448,537
Latest member
Et_Cetera

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