PC Review


Reply
Thread Tools Rate Thread

Data Validation - copy/paste

 
 
Ken Valenti
Guest
Posts: n/a
 
      17th Jun 2009
I use data validation often and know that copy/paste will not only skip
validation but also over-write the data validation. Copy/paste special will
skip validation but the rule remains in place.

Assuming I have code to re-instate the proper data validation, is there a
way to flag entries that don't comply with the data validation - or do I have
to write independent code to check entries that may have been pasted?

Excel 2003

THanks in advance!
 
Reply With Quote
 
 
 
 
Otto Moehrbach
Guest
Posts: n/a
 
      17th Jun 2009
Ken
You can use a Worksheet_Change event macro to look at the entry whenever
a change is made in the entry. That macro can then search the Data
Validation list for that entry and take whatever action you want if the
entry is not in that list. Something like the following perhaps. I assumed
your list is named MyList and the DV cell is A1. Note that this macro
resets the Data Validation in A1. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1")) Is Nothing Then
If Range("MyList").Find(What:=Target.Value, LookAt:=xlWhole) Is
Nothing Then
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
Target.Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=MyList"
End With
MsgBox "You must select from the list.", 16, "Invalid Entry"
End If
End If
End Sub
"Ken Valenti" <(E-Mail Removed)> wrote in message
news:39824950-D7A8-4969-8EEB-(E-Mail Removed)...
>I use data validation often and know that copy/paste will not only skip
> validation but also over-write the data validation. Copy/paste special
> will
> skip validation but the rule remains in place.
>
> Assuming I have code to re-instate the proper data validation, is there a
> way to flag entries that don't comply with the data validation - or do I
> have
> to write independent code to check entries that may have been pasted?
>
> Excel 2003
>
> THanks in advance!



 
Reply With Quote
 
Ken Valenti
Guest
Posts: n/a
 
      18th Jun 2009
Thanks for your reply - but that still requires to write code to match the
data validation.

Also, using a worksheet change event will disable "Undo" and since I
already have a Check Data macro that is run before submitting data to the
database, I just want to ensure that data validation has done it's job. That
way other people can change the data validation without having to change any
code.

Here's the closest thing I can come up with to do what I want.

ActiveSheet.CircleInvalid

I still don't know how to programatically check if invalid cells exist, or
what cells are invalid but, but can visibly see invalid entries.

Thanks again,

Ken

"Otto Moehrbach" wrote:

> Ken
> You can use a Worksheet_Change event macro to look at the entry whenever
> a change is made in the entry. That macro can then search the Data
> Validation list for that entry and take whatever action you want if the
> entry is not in that list. Something like the following perhaps. I assumed
> your list is named MyList and the DV cell is A1. Note that this macro
> resets the Data Validation in A1. HTH Otto
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Target.Count > 1 Then Exit Sub
> If Not Intersect(Target, Range("A1")) Is Nothing Then
> If Range("MyList").Find(What:=Target.Value, LookAt:=xlWhole) Is
> Nothing Then
> Application.EnableEvents = False
> Target.ClearContents
> Application.EnableEvents = True
> Target.Select
> With Selection.Validation
> .Delete
> .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
> Operator:= _
> xlBetween, Formula1:="=MyList"
> End With
> MsgBox "You must select from the list.", 16, "Invalid Entry"
> End If
> End If
> End Sub
> "Ken Valenti" <(E-Mail Removed)> wrote in message
> news:39824950-D7A8-4969-8EEB-(E-Mail Removed)...
> >I use data validation often and know that copy/paste will not only skip
> > validation but also over-write the data validation. Copy/paste special
> > will
> > skip validation but the rule remains in place.
> >
> > Assuming I have code to re-instate the proper data validation, is there a
> > way to flag entries that don't comply with the data validation - or do I
> > have
> > to write independent code to check entries that may have been pasted?
> >
> > Excel 2003
> >
> > THanks in advance!

>
>
>

 
Reply With Quote
 
Ken Valenti
Guest
Posts: n/a
 
      18th Jun 2009
Here's the code I was looking for

Sub IdentifyInvalidEntries()
Cells.ClearComments
Dim TempCell As Range
For Each TempCell In ActiveSheet.UsedRange
If Not TempCell.Validation.Value Then TempCell.AddComment "Invalid Entry"
Next
ActiveSheet.CircleInvalid
End Sub



"Ken Valenti" wrote:

> I use data validation often and know that copy/paste will not only skip
> validation but also over-write the data validation. Copy/paste special will
> skip validation but the rule remains in place.
>
> Assuming I have code to re-instate the proper data validation, is there a
> way to flag entries that don't comply with the data validation - or do I have
> to write independent code to check entries that may have been pasted?
>
> Excel 2003
>
> THanks in advance!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation - copy paste ! Christoffer Bloch Andersen Microsoft Excel Worksheet Functions 2 18th Mar 2009 01:22 PM
Data Validation copy and paste bug Ryan W. Microsoft Excel Discussion 1 25th Aug 2008 10:28 PM
problem data validation and copy/paste Theo Microsoft Excel Worksheet Functions 2 13th Jan 2008 08:30 PM
data validation and copy/paste....... =?Utf-8?B?TVBS?= Microsoft Excel Programming 3 27th Jul 2006 03:02 PM
Copy Paste overides data validation =?Utf-8?B?ams=?= Microsoft Excel Programming 1 23rd Jul 2006 08:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:33 AM.