ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   checking a Cells contents (https://www.excelbanter.com/excel-programming/309437-re-checking-cells-contents.html)

Don Lloyd

checking a Cells contents
 
Hi,
Variations on a theme !

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x, Ch
If Len(Target) < 9 Then GoTo Xit
For x = 1 To 9
Ch = Asc(Mid(Target, x, 1))
Select Case Ch
Case Is < 48, Is 57 '0 to 9
If x = 3 Then GoTo Xit
Case Is < 65, Is 90 'A to Z
'ALTERNATIVE Case Is < 65, 91 To 96, Is 122 'A to Z, a to z
If x < 3 Then GoTo Xit
End Select
Next x
Exit Sub
Xit:
Application.EnableEvents = False
MsgBox "Order is invalid"
Target.Select
Application.EnableEvents = True
End Sub

As is, 0 to 9 are allowed for the 3rd char. and A to Z for others.
If a to z are also permissible for others, change to the alternative given.

Regards,
Don

"antinoz" wrote in message
...
I'm trying to validate data in a column of cells to check that the format

is
"NNANNNNNN" (N= number A= Alpha I have) all the cell contents are

different
but have 9 characters containing the alphanumeric format as shown

I want to put it in an If statement:

so if cell A1 = mask "NNANNNNNNN" cell A2 = "Valid order"





All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com