|
-
Mar 25th, 2007, 03:49 PM
#1
Thread Starter
Lively Member
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
-
Mar 25th, 2007, 04:10 PM
#2
Thread Starter
Lively Member
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.
-
Mar 25th, 2007, 04:20 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 25th, 2007, 04:51 PM
#4
Thread Starter
Lively Member
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?
-
Mar 25th, 2007, 05:43 PM
#5
Re: letters
Using Mid$ and Instr you can parse each character for evaluation using a select case of valid ascii numbers.
vb Code:
select case ASC(somecharacter variable)
case 48 To 57 '0-9
'valid
case 65 To 90 'A - Z uppercase
'vaild
case 97 To 122 'a-z lowercase
'valid
case else
'invalid
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 26th, 2007, 11:26 AM
#6
Thread Starter
Lively Member
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
-
Mar 27th, 2007, 06:37 PM
#7
Re: letters
Hi
I don't know why but I always prefer Mid function to Instr
Does this help?
vb Code:
Dim str As String
str = "1aa"
'syntax of Mid in layman language is
'mid(string , start position , Length from start position)
If IsNumeric(Mid(str, 1, 1)) Then
MsgBox "Number"
Else
MsgBox "Text"
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:
Dim str As String
str = "1aa"
If Mid(str, 1, 1) = 1 Then
MsgBox "The First Character is 1"
Else
MsgBox "The First Character is not 1"
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
-
Mar 28th, 2007, 02:53 AM
#8
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|