Solved

Excel InputBox to accept text / letters only

Posted on 2013-01-24
6
693 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
  • 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 49

Expert Comment

by:Rgonzo1971
ID: 38813989
Hi,

You could refer to

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

Regards
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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