Results 1 to 17 of 17

Thread: [RESOLVED] is there a method like "isAlphabetic"

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Resolved [RESOLVED] is there a method like "isAlphabetic"

    Hello,

    I see where VBA has a method or property called "isNumeric" but i can't seem to find a similar version for the characters a to z, ie something like "isAlphbetic" or "isCharacter" ect?

    Thanks for any pointers!
    BobK

  2. #2
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: is there a method like "isAlphabetic"

    wouldn't this work for you?

    vb Code:
    1. Not isNumeric

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Re: is there a method like "isAlphabetic"

    yes that would work for the most part, but i think i'd also be pickup control characters and so on maybe?

    actually, i was hoping there would be something that would zero in on the alphabet, but i'm going to try (not IsNumeric) and see what happens!

    thanks for your response on this!
    bobk

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: is there a method like "isAlphabetic"

    Isnumeric is working on a Variant, I guess you need to check each character, if that's correct remember that the ASCII codes for alphabets are all within a defined range, use that to check if each character is alphabetical.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: is there a method like "isAlphabetic"

    Hi

    I am not sure if there is any such function or not but YES! you can create one...

    Paste this in as module.

    vb Code:
    1. Function isalpha(str As String) As Boolean
    2.  
    3. Dim Flag As Boolean
    4. Flag = True
    5.  
    6. For i = 1 To Len(Trim(str))
    7.  
    8.     If Asc(Mid(Trim(str), i, 1)) > 64 And Asc(Mid(Trim(str), i, 1)) < 90 Or _
    9.     Asc(Mid(Trim(str), i, 1)) > 96 And Asc(Mid(Trim(str), i, 1)) < 123 Then
    10.  
    11.     Else
    12.         Flag = False
    13.     End If
    14. Next i
    15.  
    16. If Flag = True Then
    17.     isalpha = True
    18. Else
    19.     isalpha = False
    20. End If
    21.  
    22. End Function

    In an excel sheet use the function as =isalpha(A1). Where A1 is the cell where you enter the word you want to test.

    If the word you entered contains all letters then the above function will return true. If even 1 letter is numeric then the above function will return false...

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Re: is there a method like "isAlphabetic"

    Thanks all, loooks good appreciate the excellent! help!

    BobK

  7. #7
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: [RESOLVED] is there a method like "isAlphabetic"

    koolsid knows too much lol

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] is there a method like "isAlphabetic"

    Thanks all, loooks good appreciate the excellent! help!
    Glad to be of help

    koolsid knows too much lol
    Thanks for the compliment but wish I knew 'that' much
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  9. #9
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: [RESOLVED] is there a method like "isAlphabetic"

    how did you get you know as much as you do?
    i'm just startin out really, playing around etc
    bought john walkenbachs new book ,been told its quite good!

  10. #10
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: [RESOLVED] is there a method like "isAlphabetic"

    lol that'll do me

  11. #11
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: [RESOLVED] is there a method like "isAlphabetic"

    Quote Originally Posted by Mitch_s_s
    bought john walkenbachs new book ,been told its quite good!
    I have his Excel 2000 edition and it is falling apart from constant use! As a 2nd book, I've found VBA Developer's Handbook by Getz to be a great follow-on....
    Last edited by VBAhack; Mar 30th, 2007 at 05:27 PM.

  12. #12
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [RESOLVED] is there a method like "isAlphabetic"

    The function could be shortened like this:
    Code:
          Function isalpha(str As String) As Boolean
          isalpha = True
          For i = 1 To Len(Trim(str))
              If Asc(Mid(Trim(str), i, 1)) > 64 And Asc(Mid(Trim(str), i, 1)) < 90 Or _
              Asc(Mid(Trim(str), i, 1)) > 96 And Asc(Mid(Trim(str), i, 1)) < 123 Then
              Else
                  isalpha = False
                  Exit Function
              End If
          Next i
          End Function
    And note that in other languages there will be more alphabetical characters (like "ä" [if this one shows on your computer]).
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  13. #13
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: [RESOLVED] is there a method like "isAlphabetic"

    Quote Originally Posted by opus
    The function could be shortened like this:
    Or this:

    Code:
    Function isalpha(str As String) As Boolean
        Dim i As Integer, k As Integer
        isalpha = True
        For i = 1 To Len(Trim(str))
            k = Asc(Mid(Trim(str), i, 1))
            If k > 64 And k < 90 Or k > 96 And k < 123 Then
            Else
                isalpha = False
                Exit Function
            End If
        Next i
    End Function

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    71

    Re: [RESOLVED] is there a method like "isAlphabetic"

    Thanks again all, super help!

    BobK

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] is there a method like "isAlphabetic"

    When you are comparing the same value multiple times in an If statement (or multiple If statements), a Select Case is more efficient..
    Code:
    Function isalpha(str As String) As Boolean
    Dim i As Integer
      isalpha = True
      For i = 1 To Len(Trim(str))
        Select Case Mid$(Trim(str), i, 1)
        Case "A" to "Z", "a" to "z"
        Case Else
          isalpha = False
          Exit For
        End Select
      Next i
    End Function
    ..using one less function (Asc) makes it more efficient too, and a bit more readable.

  16. #16
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: [RESOLVED] is there a method like "isAlphabetic"

    Nice one Si!

  17. #17
    Addicted Member
    Join Date
    Jan 2007
    Location
    England
    Posts
    234

    Re: [RESOLVED] is there a method like "isAlphabetic"

    Quote Originally Posted by VBAhack
    I have his Excel 2000 edition and it is falling apart from constant use! As a 2nd book, I've found VBA Developer's Handbood by Getz to be a great follow-on....
    thanks for that, i will look into once i've got stuck into this one!!

    Cheers!
    Last edited by Mitch_s_s; Mar 30th, 2007 at 04:33 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width