Solved

Excel InputBox to accept text / letters only

Posted on 2013-01-24
6
753 Views
Last Modified: 2013-01-29
Hello Experts,

So simple enough question that I cannot figure out or find an answer for.  In my VBA script for excel I am trying to create an input box that only accepts letters. Basically the user has to put in a persons name. No numbers, no other special characters, white space is allowed.

Can anyone show me how to do this?
0
Comment
Question by:thomashospital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:helpfinder
ID: 38813952
sorry maybe offtopic, but if it is only about person´s name and the names are known you can use Data validation feature in Excel, so you just create list of persons and users can only pick one of them.
so if you have a list and do not need VBA for some special reason this is alternative for you
sample
0
 

Author Comment

by:thomashospital
ID: 38813969
I will definitely will keep that in mind for future reference helpfinder, but in this instance they need to populate that box.
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 38813989
Hi,

You could refer to

http://vbcity.com/forums/t/148339.aspx

Regards
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 19

Assisted Solution

by:helpfinder
helpfinder earned 500 total points
ID: 38814010
Or again me and again without VBA :)
just found the formula which accepts only text characters if you put it as custom in Data validation

=AND(MIN(CODE(MID(UPPER(A1);ROW(INDIRECT("1:"&LEN(A1)));1)))>65;MAX(CODE(MID(UPPER(A1);ROW(INDIRECT("1:"&LEN(A1)));1)))< 90)

Open in new window


and now I promise I won´t reply to this threat non VBA post anymore :)
0
 

Accepted Solution

by:
thomashospital earned 0 total points
ID: 38815077
Ultimately I just figured it out.  I will post it here for the simple fact that I have searched end over end and could not find a solution to it.  Now this is not the cleanest code so feel free for anyone that uses it to clean it up.  To give credit a piece of this was taken from Mr.Excel.com

Range("d3") = InputBox("Copy over patient info")
    If Asc(Range("d3")) > 64 And Asc(Range("d3")) < 91 Then
    ElseIf Asc(Range("d3")) > 96 And Asc(Range("d3")) < 123 Then
       Else
        Do
            MsgBox "Invalid entry"
            Call AscTest
            Loop Until Asc(Range("d3")) > 64 And Asc(Range("d3")) < 91 Or Asc(Range("d3")) > 96 And Asc(Range("d3")) < 123
    End If

End Sub

Sub AscTest()
Range("d3") = InputBox("Copy over patient info")
    If Asc(Range("d3")) > 64 And Asc(Range("d3")) < 91 Then
        
    ElseIf Asc(Range("d3")) > 96 And Asc(Range("d3")) < 123 Then
        
    Else
        MsgBox "Invalid entry"
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:thomashospital
ID: 38830313
Thanks for all the help and feedback!
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question