Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I restrict an inputbox to 5<= string characters?

I am still new with VBA...

I need help writing a macro that will restrict an input to 1 to 5
characters of the alphabet. This input should be prompted using the
application.inputbox function.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I restrict an inputbox to 5<= string characters?


If you are referring to an inputbox on a userform, you set the
"MaxLength" property to 5 in the VBE, or if you want to do it
programatically, you would use textbox1.maxlength = 5.

If you want, you can also have the focus move to the next control
(tabindex) when the max length is reached by setting the "AutoTab"
property to true

To restrict only alphabetic inputs use

Private Sub textbox1_keypress(ByVal keyascii As MSForms.ReturnInteger)
Select Case keyascii
Case Asc("a") To Asc("z")
case asc("A") to asc("Z")
Case Else: keyascii = 0
End Select
End Sub

This will allow only upper and lower case letters to be entered in the
inputbox.


--
bgeier
------------------------------------------------------------------------
bgeier's Profile: http://www.excelforum.com/member.php...o&userid=12822
View this thread: http://www.excelforum.com/showthread...hreadid=541777

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I restrict a text column to a specific number of characters? Irene Threadgold Excel Discussion (Misc queries) 4 November 5th 09 09:31 PM
Insert Leading Characters If String Is Only 7 Characters Paperback Writer Excel Discussion (Misc queries) 2 April 21st 09 09:07 PM
preventing input of illegal characters in an inputbox drofnats Excel Programming 8 July 11th 04 09:25 PM
InputBox function - prompt string limit Marcotte A[_2_] Excel Programming 4 June 9th 04 09:47 AM
Fix InputBox - Returning Empty String spurtniq[_3_] Excel Programming 7 December 31st 03 06:23 PM


All times are GMT +1. The time now is 10:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"