Restricting Characters within a User Form

  • Thread starter Thread starter DarnTootn
  • Start date Start date
Try some code like the following.


Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim C As String
With Me.TextBox1
If Len(.Text) = 0 Then
Exit Sub
End If
C = Right(.Text, 1)
Select Case C
Case "a", "b", "c"
' allowed
Case Else
' anything else is prohibited
.Text = Left(.Text, Len(.Text) - 1)
End Select
End With
End Sub


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
I think with a few "tweaks" to it, this will work perfectly. Thanks again!!
If it weren't for folks like yourself that contribute to these discussion
groups I would never get anything done and would be spending my time in
professional training courses to get the same kind of information that I get
from this group. THANKS TO ALL !!
 
Again, Thank you to all those that contribute to this disscussion group.
THIS ONE WORKS GREAT THANKS CHIP!!!!!
 
Back
Top