+ Reply to Thread
Results 1 to 2 of 2

ActiveX TextBox

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2019
    Location
    London
    MS-Off Ver
    2018
    Posts
    20

    ActiveX TextBox

    I have a problem with my macro that runs in UserForm and I would also like to apply it to sheet1 in textBox active controls. I have a question how to change the code to work in sheat1?

    Option Explicit
    
    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
       If Not IsNumeric(Chr(KeyAscii)) And Not KeyAscii = 8 Then
          KeyAscii = 0
       End If
    End Sub
    
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox1.Value = "" Then
    Exit Sub
    End If
       If Val(TextBox1.Text) < 100 Or Val(TextBox1.Text) > 999 Then
          MsgBox "Error"
          Cancel = True
       End If
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: ActiveX TextBox

    The Exit event is not available on the worksheet so use the LostFocus event instead.

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
       If Not IsNumeric(Chr(KeyAscii)) And Not KeyAscii = 8 Then
          KeyAscii = 0
       End If
    End Sub
    
    Private Sub TextBox1_LostFocus()
        If TextBox1.Value <> "" Then
            If Val(TextBox1.Text) < 100 Or Val(TextBox1.Text) > 999 Then
                MsgBox "Error"
            End If
        End If
    End Sub
    Code should be within the worksheet object holding the control
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Use TAB Key to go to the next TextBox (Activex)
    By danallamas in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-27-2018, 05:41 AM
  2. ActiveX Textbox vs. Regular textbox
    By JennaM in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2017, 03:10 PM
  3. [SOLVED] Change ActiveX textbox text when I have the textbox name in a variable
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2017, 08:37 AM
  4. ActiveX Textbox
    By Lana74 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-12-2016, 05:12 PM
  5. Multi-Worksheet ActiveX Textbox to ActiveX Textbox Concatenate
    By HVE_Skynet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2014, 02:11 PM
  6. ActiveX Textbox to ActiveX Textbox Concatentate
    By HVE_Skynet in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2014, 05:22 PM
  7. TextBox (ActiveX).Value
    By way2suresh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2013, 05:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1