PC Review


Reply
Thread Tools Rate Thread

Data validation vs. cutting pasting

 
 
=?Utf-8?B?SWxseWEgVGVpZGVtYW4=?=
Guest
Posts: n/a
 
      22nd Aug 2007
Does anyone know a way to allow data to be copied and pasted into a
spreadsheet that contains data validation in some areas and retain the
validation on those cells? Ideally I would like the ability to allow the
operation under all circumstances unless the action breaches one or more
validation rules.
Whatever the solution it must be able to handle:
1. One cell copied to one cell in the same sheet when target cell has
validation
2. One cell copied to one cell in the same sheet when target cell has no
validation
3. A block of cells copied to to a block of cells in the same sheet where no
cells have validation
4. A block of cells copied to to a block of cells in the same sheet where
ALL cells have validation
5. A block of cells copied to to a block of cells in the same sheet where
some but not all cells have validation
And all of the above if the copied cell / data comes from outside the sheet
/ workbook.

So far I have tried some VBA code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Does the validation range still have validation?
If HasValidation(Range("ValidationRange")) Then
Exit Sub
Else
Application.Undo
MsgBox "Your last operation was canceled." & _
"It would have deleted data validation rules.", 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

This works unless you copy a block of data from outside the sheet. It's also
not too flexible but I feel it's on the right lines.

What would be good is to be able to lock down the range of cells containing
validation to prevent them being able to be pasted on even in a block but
still allow manual entry.
 
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
Cutting row data and pasting into next available row on different tab Neil Microsoft Excel Programming 2 28th Feb 2011 08:57 PM
HELP! - Cutting and Pasting Data into Text Box? Trng_Chickster Microsoft Access Forms 2 3rd Feb 2010 02:43 PM
Data Aligning with out cutting and pasting Earl Tewksbury Microsoft Excel Worksheet Functions 2 10th Feb 2009 08:39 PM
Cutting pasting data to an existing template AnneOlly Microsoft Excel Programming 0 3rd Apr 2008 03:28 PM
Re: I was cutting and pasting from a website and I now have a data in. Dave Peterson Microsoft Excel Misc 0 9th Sep 2004 02:11 AM


Features
 

Advertising
 

Newsgroups
 


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