How to allow only data validated text to cells

aek_nikos

New Member
Joined
Jan 12, 2023
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have data validated cells i.e E4:L40 and data allowed is a list in cells Q52:Q80. Data validation is not working when someone c/p and the only VBA code i could find is one that forbids c/p totally. That's not helpful because i want to give editor's permition to c/p if the text, they want to c/p, is from the list (Q52:Q80)

(list and validated cells are not the same in every sheet but if i could find a VBA code i'll be OK)
Any thoughts?
Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If you want the users to be able to copy and paste the data into the range then they need to be sure the data that is being pasted is already validated against the allowed list. Validation does not process in copy/paste scenarios.
 
Upvote 0
If you want the users to be able to copy and paste the data into the range then they need to be sure the data that is being pasted is already validated against the allowed list. Validation does not process in copy/paste scenarios.
@aek_nikos
Additionally if you do a regular paste into the range of cells with data validation, you remove the validation from those cells. In the example below, I have pasted invalid data with "data only" and the paste was still permitted.

Some Mr Excel Questions.xlsx
ABCDE
2
3Select by DropPastedValid ValuesInvalid Values
4MACA
5CBDB
6PEGE
7PFHF
8QIMI
9TJNJ
10MKPK
11QLPL
12TOQO
13TR
14S
15U
16V
17W
18X
19Y
20Z
Sheet1
Cells with Data Validation
CellAllowCriteria
A13:A15List=Valid_Values
A4:B12List=Valid_Values
 
Upvote 0
try adding this to sheet code

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rg As Range
If Not Intersect(Target, Range("E4:L40")) Is Nothing Then
Set rg = Range("Q52:Q80").Find(Intersect(Target, Range("E4:L40")), Lookat:=xlWhole, LookIn:=xlValues)
    If rg Is Nothing Then
    Application.EnableEvents = False
    Application.Undo
        MsgBox "SELECT FROM DROPDOWN LIST", vbOKOnly, "INVAILD VALUE" ' MsgBox row is Optional
    Application.EnableEvents = True
        Exit Sub
    End If
End If
End Sub
 
Upvote 0
Solution
try adding this to sheet code

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rg As Range
If Not Intersect(Target, Range("E4:L40")) Is Nothing Then
Set rg = Range("Q52:Q80").Find(Intersect(Target, Range("E4:L40")), Lookat:=xlWhole, LookIn:=xlValues)
    If rg Is Nothing Then
    Application.EnableEvents = False
    Application.Undo
        MsgBox "SELECT FROM DROPDOWN LIST", vbOKOnly, "INVAILD VALUE" ' MsgBox row is Optional
    Application.EnableEvents = True
        Exit Sub
    End If
End If
End Sub
Thanks a lot for your answer but it didn't work. C/P of non-validated text is still allowed. Just for being sure i am not mistaken: Your code isn't an addition to an existing code, it's the full code. Correct?

Appreciate your time
 
Upvote 0
It’s a full code. Just to be sure your not using this as a macro. Right click on the sheet name at the bottom click on view code and paste this code on the sheet
 
Upvote 0
YESSSSSSSSSS!
You are awesome!
I was using it as a macro!
Thanks a lot
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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