I am using data validation on a column by a predefined list.
but it can be easily fooled or bypassed by pasting (Ctrl+V) data from other source.
So how can i protect to user can't enter wrong data or outside from my validation list.
Try using paste hooks/handlers to prevent this from occurring.
It's something of a hack, but in your VBA you can bind custom functions to the commonly used key/click actions that fire "paste" events. Those custom functions can access the selection affected by the paste, and fire validation rules/custom subs on it immediately. For examples of this functionality, try this guide (especially the section farther down titled "Validation").
This doesn't prevent users from pasting invalid data in the first place, but results in the immediate revocation of invalid data, which might be close enough to the same thing for your purposes.
If intercepting Paste events seems complex then an alternative solution is to just use the
BeforeSave event of the workbook. In this, check the value(s) and, if any are incorrect, cancel the Save by setting
Cancel = True
You could use the
Deactivate event of a worksheet but this doesn't offer a simple way to cancel the deactivation, but a warning
MsgBox could be shown.
Rahul, I am working on a similar problem right now. Having read a number of the Excel forums and the MS help boards on this issue, I can tell you that it's really TWO problems:
A) a standard copy-paste in Excel copies the validations from the source to the destination. If you don't have any safeguards, this wipes out the validation from your special column when a user pastes into it. B) Excel only performs validation on single cells and not on paste actions. Pretty weak.
I can solve problem A for you; I think you will need VBA to do custom validation for problem B. See the links at the bottom of this post for some ideas; I'm not a pro at VBA so I can't really say which will work for you.
For problem A: go to the Review tab and turn Protection on at either the sheet or workbook level :) I haven't seen anyone else mention this solution, but it works really well. When protection is turned on, the user cannot overwrite the validations in your column with a paste.
The default rights for a user in a protected sheet are pretty minimal. If your users need a lot of rights, like the ability to delete rows, just enable the rights they need in the Protect dialog by checking the checkboxes. I have everything enabled except Insert Hyperlinks and I still can't overwrite validation when protection is turned on.
Here are some relevant links for you: