Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Validation on Pasted Values in Excel

Status
Not open for further replies.

grnzbra

Programmer
Mar 12, 2002
1,273
US
I have set size limits on some fields using Data Validation. This works fine when a value is typed in, but if the value is pasted in this doesn't seem to work. Is there a way to make the Data Validation rules apply to pasted values as well as those typed in?
(Or is there a way to prevent values from being pasted into a workbook?)
 
Data validation fires when cell is edited. A partial solution may be clearing office clipboard with VBA when a cell with DV is selected:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
  If Not Intersect(Target, CellWithDV_Reference) Is Nothing Then
    Application.CutCopyMode = False
  End If
End Sub
May be unpleasant when user copy something, select cell with DV and does not plan to paste.

An alternative Worksheet_Change event procedure requires duplicating DV limits rules in VBA. Hovever, in this case DV can be used only to display entry messages, Application.Undo will take back last user action if value entered/copied is outside permitted range.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top