Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 811
  • Last Modified:

Excel InputBox to accept text / letters only

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
thomashospital
Asked:
thomashospital
  • 3
  • 2
2 Solutions
 
helpfinderCommented:
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
 
thomashospitalAuthor Commented:
I will definitely will keep that in mind for future reference helpfinder, but in this instance they need to populate that box.
0
 
Rgonzo1971Commented:
Hi,

You could refer to

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

Regards
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
helpfinderCommented:
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
 
thomashospitalAuthor Commented:
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
 
thomashospitalAuthor Commented:
Thanks for all the help and feedback!
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now