View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove[_2_] Harlan Grove[_2_] is offline
external usenet poster
 
Posts: 1,231
Default A validation rule on Alpha and Numeric characters

"Rick Rothstein \(MVP - VB\)" wrote...
....
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 1 Or Target.Value = "" Then Exit Sub
If Not Target.Value Like "[A-Za-z][A-Za-z][A-Za-z]####" Then
MsgBox "Wrong Format!"
Target.Value = ""


Very bad! At least use Application.Undo rather than setting the target
cell's value to "", which can't be undone. Also, Target COULD be a
multiple cell range, which would make it an even worse idea to set all
cells to "".

Target.Activate
End If
End Sub

....

Event handlers only work when macros are enabled, and it's simple for
users to disable macros. Data validation ALWAYS works.