if statement using alpha characters

M

mikey may

I am wanting to use an IF statment to check if a value of
the 3 digit of 'AccRef'is alphabetical using the following
code

AccRef = LGD12345

If Mid(AccRef, 3, 1) < "a" Or Mid(AccRef, 3, 1) > "z" Then

This doesn't seem to work properly and was wondering if
there is a different way of doing the above.

The 3rd digit will always be an alpha character
 
T

Ture Magnusson

Mickey,

If LCASE and UCASE are the same, it's not a letter...

Sub Test()
Dim accref As String
accref = "LGD12345"
If UCase(Mid(accref, 3, 1)) = LCase(Mid(accref, 3, 1)) Then
MsgBox "Sorry. Not a letter"
End If
End Sub

It is also possible to do a similar test with in a worksheet formula:

= NOT(EXACT(UPPER(MID(A1,3,1)),LOWER(MID(A1,3,1))))
 
Top