Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default User Form Controls


"Ben E" wrote in message
...
Hi all,

Is it possible within a excel user form to set a text box
to:

1) only accept numbers
2) only accept a set number of characters

Ie the user can only input a 4 number code.


Ben E


The best option is probably to use the textbox change event
the example below will only permit numbers to be entered


Private Sub TextBox1_Change()
Dim keyascii As Integer
If TextBox1.Text < "" Then
keyascii = Asc(Right(TextBox1.Text, 1))

If keyascii 47 And keyascii < 58 Then
' If its a number allow it
Else
' Else throw away the change
TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)

End If
End If

End Sub




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
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
User Form Controls Tom Ogilvy Excel Programming 0 August 29th 03 12:42 PM
User Form Controls Zaid Qureshi Excel Programming 0 August 29th 03 12:40 PM
User Form Controls Zaid Qureshi Excel Programming 0 August 29th 03 12:40 PM
user form controls chris gee Excel Programming 0 July 15th 03 12:05 AM


All times are GMT +1. The time now is 11:12 AM.

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

About Us

"It's about Microsoft Excel"