Solved

Excel InputBox to accept text / letters only

Posted on 2013-01-24
6
648 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 48

Expert Comment

by:Rgonzo1971
ID: 38813989
Hi,

You could refer to

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

Regards
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Service to Receive TCP Packets 4 48
Excel 6 19
Recommendation vb6 to vb.net or others 14 41
Column Formatting 4 6
Outlook Free & Paid Tools
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now