Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
I need a function in VBA like "isNumeric" that checks if a string only
contains alaphabetic characters. Would love some help. Thanks CR |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
how about
Function IsAlpha(s as string) IsAlpha = (ucase(s) like [A-Z]) end function ? Tim "C. Roenbaugh" wrote in message oups.com... I need a function in VBA like "isNumeric" that checks if a string only contains alaphabetic characters. Would love some help. Thanks CR |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
Thanks Tim
Here is what i used, but i will try your suggestion. nonAlpha = 0 For j = 1 To Len(userPassword) Select Case Asc(Mid(userPassword, j, 1)) Case 0 To 47, 58 To 64, 123 To 256 nonAlpha = nonAlpha + 1 Case 48 To 57, 65 To 122 nonAlpha = nonAlpha + 0 End Select Next j |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
Function IsAlpha(s As String)
IsAlpha = (UCase(s) Like "[A-Z]") End Function Think it would be a little more complex than that: ? isalpha("abc") False -- Regards, Tom Ogilvy "Tim Williams" <saxifrax at pacbell dot net wrote in message ... how about Function IsAlpha(s as string) IsAlpha = (ucase(s) like [A-Z]) end function ? Tim "C. Roenbaugh" wrote in message oups.com... I need a function in VBA like "isNumeric" that checks if a string only contains alaphabetic characters. Would love some help. Thanks CR |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
I believe this does what you're asking for:
Function IsAlpha(entry) As String Dim i As Integer Dim c As Variant Dim OK As Boolean i = 1 For i = 1 To Len(entry) c = Mid(entry, i, 1) If (UCase(c) Like "[A-Z]") Then OK = True Else OK = False End If If OK = False Then IsAlpha = False Exit Function End If Next i IsAlpha = True End Function Regards, Anita |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
C.R., If you want to check for the condition that ALL characters in a STRING are alphanumeric and that the presence of even one non-alphanumeric should return "FALSEHOOD", you may need to tweak your code thus: Function CheckForAlphaNumeric(txt As String) For j = 1 To Len(txt) Select Case Asc(Mid(txt, j, 1)) Case 0 To 47, 58 To 64, 91 To 96, 123 To 256 CheckForAlphaNumeric = "NON-ALPHANUMERIC FOUND" Exit Function Case 48 To 57, 65 To 90, 97 To 122 'or simply CASE ELSE End Select Next j CheckForAlphaNumeric = "ALL ALPHANUMERIC" End Function Note that I have had to recalibrate the select case ranges to fully segregate the alphanumerics from the non-alphanumerics. -- Myles ------------------------------------------------------------------------ Myles's Profile: http://www.excelforum.com/member.php...o&userid=28746 View this thread: http://www.excelforum.com/showthread...hreadid=503875 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
Without using a Regular Expression, would this work for you?
Function AllAlpha(s As String) As Boolean AllAlpha = UCase(s) Like WorksheetFunction.Rept("[A-Z]", Len(s)) End Function HTH :) -- Dana DeLouis Win XP & Office 2003 "C. Roenbaugh" wrote in message oups.com... I need a function in VBA like "isNumeric" that checks if a string only contains alaphabetic characters. Would love some help. Thanks CR |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
My bad - poor reading of the Help...
Tim "Tom Ogilvy" wrote in message ... Function IsAlpha(s As String) IsAlpha = (UCase(s) Like "[A-Z]") End Function Think it would be a little more complex than that: ? isalpha("abc") False -- Regards, Tom Ogilvy "Tim Williams" <saxifrax at pacbell dot net wrote in message ... how about Function IsAlpha(s as string) IsAlpha = (ucase(s) like [A-Z]) end function ? Tim "C. Roenbaugh" wrote in message oups.com... I need a function in VBA like "isNumeric" that checks if a string only contains alaphabetic characters. Would love some help. Thanks CR |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Is Alaphabetic
of all the replies I've seen, I think that your own code in the end is the
better INHO The cjhnage I made was to specify what IS a good character - its a heck easier that excluding stuff.... Function IsAlpha(s As String) As Boolean Dim letter As String Dim index As Long ' note defailt is FALSE IsAlpha = True For index = 1 To Len(s) letter = Mid(s, index, 1) Select Case Asc(letter) Case 32, 48 To 57, 65 To 90, 97 To 122: 'OK Case Else IsAlpha = False Exit For End Select Next End Function "C. Roenbaugh" wrote: I need a function in VBA like "isNumeric" that checks if a string only contains alaphabetic characters. Would love some help. Thanks CR |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|