Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,670
Default Data Validation/Cell Protection Question

I distribute a worksheet to many users to supply standardized data inputs and
it includes a lot of validation and cell protection to prevent creativity.
Someone beat my data validation rule for a cell by simply copying & pasting
another cell over it.

In simple terms:
Valid entries for Column A (using a list/dropdown) are odd numbers 1, 3, 5,
7, 9
Valid entries for Column B (using a list/dropdown) are even numbers 2, 4, 6, 8

Copying and pasting cell A1 into B1 allowed someone to get an odd number
into B1.

Additional cell protection in A&B keeps jumping into my mind, but each time
I think about it, I realize protection runs contrary to allowing data input.
Or does it ?

Any suggestions for keeping copy/pasters from getting invalid data into
Column B?

TIA.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Data Validation/Cell Protection Question

On May 10, 6:29 am, Eric wrote:
I distribute a worksheet to many users to supply standardized data inputs and
it includes a lot of validation and cell protection to prevent creativity.
Someone beat my data validation rule for a cell by simply copying & pasting
another cell over it.

In simple terms:
Valid entries for Column A (using a list/dropdown) are odd numbers 1, 3, 5,
7, 9
Valid entries for Column B (using a list/dropdown) are even numbers 2, 4, 6, 8

Copying and pasting cell A1 into B1 allowed someone to get an odd number
into B1.

Additional cell protection in A&B keeps jumping into my mind, but each time
I think about it, I realize protection runs contrary to allowing data input.
Or does it ?

Any suggestions for keeping copy/pasters from getting invalid data into
Column B?

TIA.


Maybe back up your data validation with a WorksheetChange Event
procedure to deal with copy/pasters.
Something like...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:B")) Is Nothing Then
On Error GoTo ErrorHandler
Dim rgCell As Range
Dim strInvalidCells As String
For Each rgCell In Target.Cells
If rgCell.Value < "" Then
With rgCell
If (.Value Mod 2 = 0 And .Column = 1) _
Or (.Value Mod 2 = 1 And .Column = 2) Then
strInvalidCells = strInvalidCells _
& .Value & " in " _
& .Address(False, False) & ", "
Application.EnableEvents = False
.ClearContents
Application.EnableEvents = True
End If
End With
End If
Next rgCell
If Len(strInvalidCells) 0 Then
strInvalidCells = Left(strInvalidCells, _
Len(strInvalidCells) - 2)
MsgBox "Even column A and Odd column B values are invalid!" _
& vbNewLine & _
"The following have been cleared because they were invalid..." _
& vbNewLine & strInvalidCells
End If
Exit Sub
ErrorHandler: Application.EnableEvents = True
End If
End Sub

Ken Johnson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Data Validation/Cell Protection Question

Sorry, I didn't restrict value to the range you indicated, so should
be...

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A:B")) Is Nothing Then
On Error GoTo ErrorHandler
Dim rgCell As Range
Dim strInvalidCells As String
For Each rgCell In Target.Cells
If rgCell.Value < "" Then
Select Case rgCell.Column
Case 1
Select Case rgCell.Value
Case 1, 3, 5, 7, 9
Case Else
With rgCell
strInvalidCells = strInvalidCells _
& .Value & " in " _
& .Address(False, False) & ", "
Application.EnableEvents = False
.ClearContents
Application.EnableEvents = True
End With
End Select
Case 2
Select Case rgCell.Value
Case 2, 4, 6, 8
Case Else
With rgCell
strInvalidCells = strInvalidCells _
& .Value & " in " _
& .Address(False, False) & ", "
Application.EnableEvents = False
.ClearContents
Application.EnableEvents = True
End With
End Select
End Select
End If
Next rgCell
If Len(strInvalidCells) 0 Then
strInvalidCells = Left(strInvalidCells, _
Len(strInvalidCells) - 2)
MsgBox "Even column A and Odd column B values are invalid!" _
& vbNewLine & _
"The following have been cleared because they were invalid..." _
& vbNewLine & strInvalidCells
End If
Exit Sub
ErrorHandler: Application.EnableEvents = True
End If
End Sub

Ken Johnson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation and Cell Protection DLS2007 Excel Discussion (Misc queries) 0 September 24th 07 11:22 PM
Worksheet protection interfering with data validation combo box pr Lele Excel Discussion (Misc queries) 1 March 4th 07 07:51 PM
Data Validation Protection LRodgers Excel Discussion (Misc queries) 2 May 24th 06 03:41 PM
data validation and cell protection jerrystan Excel Discussion (Misc queries) 0 January 19th 06 06:58 PM
Data validation, cell protection or other method? KG Excel Discussion (Misc queries) 5 June 17th 05 05:22 AM


All times are GMT +1. The time now is 12:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"