Results 1 to 4 of 4

UserForm keypress event help

This is a discussion on UserForm keypress event help within the Excel Questions forums, part of the Question Forums category; Hi I am trying to restrict text in a textbox on a userform. So I use Private Sub TextBox1_KeyPress(ByVal KeyAscii ...

  1. #1
    DRJ
    DRJ is offline
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,856

    Default UserForm keypress event help

    Hi

    I am trying to restrict text in a textbox on a userform. So I use

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

    End Sub

    This works fine, but I have like 20 textboxs on one userform and I wanted to not have to put this code 20 seperate times.

    I tried

    Private Sub Userform1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0

    End Sub

    but it didnt seem to work. Like I said it will work fine if I report the code 20 times once for each textbox, but is there a simple way to include all the textboxs as one?

    Thanks

    Jacob

  2. #2
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: UserForm keypress event help

    Please keep all posts to the original thread.

    http://www.mrexcel.com/board2/viewtopic.php?t=64518

  3. #3
    DRJ
    DRJ is offline
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,856

    Default Re: UserForm keypress event help

    This is a different question

  4. #4
    MrExcel MVP TommyGun's Avatar
    Join Date
    Dec 2002
    Location
    Clear Lake, TX
    Posts
    4,202

    Default Re: UserForm keypress event help

    http://www.mrexcel.com/board2/viewtopic.php?t=53597

    NOTE: Different question, but related topic. Multiple threads slow down the board. Please keep all related questions to the same thread.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com