Results 1 to 8 of 8

Thread: letters

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    110

    letters

    what is the symbol in excel for a letter and for a number. e.g. to check that a user input began and ended with a letter and that the secong digit was a number etc.
    thanks joe

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    110

    Re: letters

    sorry i meant in vba

    e.g. for this code

    Code:
    Private Sub TextBox9_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    TextBox9.Text = Trim(TextBox9.Text)
    
    Dim strPhone As String
    strPhone = Replace(TextBox9.Text, " ", "")
    
    If Len(strPhone) = 6 Or 7 And InStr(1, strPhone, "here i want to put the symbol for a letter or integer") = 1 Then
    strPhone = Mid(strPhone, 1, 4) & " " & Mid(strPhone, 5, Len(strPhone) - 4)
    TextBox9.Text = strPhone
    
    Else
    MsgBox TextBox9.Text & " is not a valid post code. Please enter a valid post code."
    TextBox9.Text = ""
    TextBox9.SetFocus
    Cancel = True
    End If
    
    End Sub
    i hope this makes it abit easier to understand what i want to do.

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: letters

    Use either IsNumeric or evaluate the character at the desired position for its acceptable ASCII character code. If its certain ASCII values then you know its a number or char or symbol etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    110

    Re: letters

    i cant use isnumeric because it has both in and i need to check that each character is in the right place. how do i use the method you mentioned?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: letters

    Using Mid$ and Instr you can parse each character for evaluation using a select case of valid ascii numbers.


    vb Code:
    1. select case ASC(somecharacter variable)
    2.     case 48 To 57 '0-9
    3.         'valid
    4.     case 65 To 90 'A - Z uppercase
    5.         'vaild
    6.     case 97 To 122 'a-z lowercase
    7.         'valid
    8.     case else
    9.         'invalid
    10. end select
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    110

    Re: letters

    back to the isnumeric thing, is it possible to use it in the instr function e.g. like this

    InStr(1, strPhone, isnumeric) = 1

    thanks joe

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

    Re: letters

    Hi

    I don't know why but I always prefer Mid function to Instr

    Does this help?

    vb Code:
    1. Dim str As String
    2.  
    3. str = "1aa"
    4.  
    5. 'syntax of Mid in layman language is
    6. 'mid(string , start position , Length from start position)
    7. If IsNumeric(Mid(str, 1, 1)) Then
    8.     MsgBox "Number"
    9. Else
    10.     MsgBox "Text"
    11. End If

    InStr(1, strPhone, isnumeric) = 1
    If you want to check if the 1st character in the above string is 1 then this should help...
    vb Code:
    1. Dim str As String
    2.  
    3. str = "1aa"
    4.  
    5. If Mid(str, 1, 1) = 1 Then
    6.     MsgBox "The First Character is 1"
    7. Else
    8.     MsgBox "The First Character is not 1"
    9. End If

    Hope this helps...
    Last edited by Siddharth Rout; Mar 27th, 2007 at 06:42 PM. Reason: Spelling Error
    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

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    110

    Re: letters

    i will use this method if i cant match up the user inputted postcode to a list of postcodes in another sheet

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