View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default A validation rule on Alpha and Numeric characters

I want to create a validation that when i enter a mixed numeric and alpha
reference that i can prevent changing its format.

For example:

Everytime i enter my "number" FEE1234, that the cell keeps the formatting
"@@@####" and prevents me using any other format indicating n error
message.


Assuming that @@@ means the first 3 characters are either upper or lower
case **letters** from the alphabet only, does this Worksheet Macro do what
you want?

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 = ""
Target.Activate
End If
End Sub

where you would change the number 1 in 'Target.Column < 1' to the column
number you want to filter (and, of course, change the MessageBox message
also).

Rick