+ Reply to Thread
Results 1 to 9 of 9

Is Alaphabetic

  1. #1
    C. Roenbaugh
    Guest

    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. #2
    Tim Williams
    Guest

    Re: Is Alaphabetic

    how about

    Function IsAlpha(s as string)
    IsAlpha = (ucase(s) like [A-Z])
    end function

    ?
    Tim

    "C. Roenbaugh" <[email protected]> wrote in message
    news:[email protected]...
    >I need a function in VBA like "isNumeric" that checks if a string only
    > contains alaphabetic characters. Would love some help.
    >
    > Thanks
    >
    > CR
    >




  3. #3
    C. Roenbaugh
    Guest

    Re: 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. #4
    Tom Ogilvy
    Guest

    Re: 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
    news:[email protected]...
    > how about
    >
    > Function IsAlpha(s as string)
    > IsAlpha = (ucase(s) like [A-Z])
    > end function
    >
    > ?
    > Tim
    >
    > "C. Roenbaugh" <[email protected]> wrote in message
    > news:[email protected]...
    > >I need a function in VBA like "isNumeric" that checks if a string only
    > > contains alaphabetic characters. Would love some help.
    > >
    > > Thanks
    > >
    > > CR
    > >

    >
    >




  5. #5
    Anita
    Guest

    Re: 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. #6
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    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
    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.

    If you wish to check for ALPHABETS ONLY (and not ALPHANUMERICS as your attempted code suggested), then use:

    Function CheckForAlphasOnly(txt As String)

    For j = 1 To Len(txt)
    Select Case Asc(Mid(txt, j, 1))
    Case 0 To 64, 91 To 96, 123 To 256
    CheckForAlphasOnly = "NON-ALPHAS FOUND"
    Exit Function
    End Select
    Next j
    CheckForAlphasOnly = "ALL ALPHAS"

    End Function
    Last edited by Myles; 01-23-2006 at 12:22 AM.

  7. #7
    Dana DeLouis
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >I need a function in VBA like "isNumeric" that checks if a string only
    > contains alaphabetic characters. Would love some help.
    >
    > Thanks
    >
    > CR
    >




  8. #8
    Tim Williams
    Guest

    Re: Is Alaphabetic

    My bad - poor reading of the Help...

    Tim

    "Tom Ogilvy" <[email protected]> wrote in message
    news:%[email protected]...
    > 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
    > news:[email protected]...
    >> how about
    >>
    >> Function IsAlpha(s as string)
    >> IsAlpha = (ucase(s) like [A-Z])
    >> end function
    >>
    >> ?
    >> Tim
    >>
    >> "C. Roenbaugh" <[email protected]> wrote in message
    >> news:[email protected]...
    >> >I need a function in VBA like "isNumeric" that checks if a string only
    >> > contains alaphabetic characters. Would love some help.
    >> >
    >> > Thanks
    >> >
    >> > CR
    >> >

    >>
    >>

    >
    >




  9. #9
    Patrick Molloy
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1