98.8% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel Training and help » Drop Down protection
Drop Down protection
Resolved · Medium Priority · Version 2010
Warren has attended:
Excel Advanced course
Drop Down protection
How do you prevent a user copying and pasting a value over a drop-down?
RE: Drop Down protection
Hi Warren,
This has been a problem since Excel began! Pasting values over the top will remove data validation. If a cell can be edited, then pasting can break it. This is due to Excel functioning as a data analytical programme not as a Database program such as Access.
There is a work around using VBA code to constantly check the sheet for changes.
It would look something like this
Private Sub Worksheet_Change(ByVal Target As Range)
'Does the validation range still have validation?
If HasValidation(Range("DataValidationRange")) Then
Exit Sub
Else
Application.Undo
MsgBox "Error: You cannot paste data into these cells." & _
"Please use the drop-down to enter data instead.", vbCritical
End If
End Sub
Private Function HasValidation(r) As Boolean
'Returns True if every cell in Range r uses Data Validation
On Error Resume Next
x = r.Validation.Type
If Err.Number = 0 Then HasValidation = True Else HasValidation = False
End Function
Kind regards
Richard Bailey
Microsoft Certified Trainer
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
Wed 7 Sep 2016: Automatically marked as resolved.
Training information:
See also:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Generating Random NumbersTo generate a random number in Excel use the = RAND() function. |