Not allow paste, but allow VBA code to paste
vcoolio Posts 1411 Registration date Thursday July 24, 2014 Status Moderator Last seen September 6, 2024 - Sep 6, 2024 at 08:39 PM
- Not allow paste, but allow VBA code to paste
- Battery reset code - Guide
- How to get whatsapp verification code online - Guide
- Samsung volume increase code - Guide
- Samsung keypad reset code - Guide
- Vba case like - Guide
2 responses
Sep 6, 2024 at 03:21 AM
Hello Sean
Is there a way to prevent the users from pasting whole rows or columns
The old fashioned way would be to give the offender a clip under the ear!
Data validation has always been a problem to keep safe from overwriting.
However, you could try something like this code:
Private Sub Worksheet_Change(ByVal Target As Range) Dim tVal As String, ListVal As String, ListVal2 As String If Target.Count > 1 Then Exit Sub Application.EnableEvents = False tVal = Target.Value On Error Resume Next ListVal = Target.Validation.InCellDropdown On Error GoTo 0 Application.Undo On Error Resume Next ListVal2 = Target.Validation.InCellDropdown On Error GoTo 0 If ListVal = ListVal2 Then Target = tVal Else MsgBox "DO NOT ATTEMPT TO PASTE VALUES INTO DATA VALIDATED CELLS. PLEASE USE THE DROP DOWN VALUES ONLY.", vbExclamation, "WARNING" End If Application.EnableEvents = True Application.CutCopyMode = False End Sub
Please note that this works at the WorkSheet level not the WorkBook level as your other code does. Hence, this code needs to be placed in the worksheet module of the affected worksheet (I'm assuming this is what you'd like).
Test it in a copy of your workbook first and see what happens.
Cheerio,
vcoolio.
Sep 6, 2024 at 08:39 PM
Hello Sean,
Hmmm.....viciouscoolio. Has a certain ring to it!
It'd probably be best to upload your sample workbook with all the codes you have in it left in their modules. I'll have a play with it before I once again disappear from the forum.
Should I remove the original code?
Nope. I'll check it out and see how it interacts with the code in post #1.
Have a great weekend!
Cheerio,
vcoolio.
Sep 6, 2024 at 10:49 AM
Now I know what the v stands for in vcoolio... vicious!
I tried the code on my test workbook to no avail. I pasted it to each sheet as you suggested and left the original code in place. Should I remove the ofiginal code?
The data validation stop I have in does work if you type anything other than Open or Closed. However, not against the evil paste action... mua hahahaha!