none
EXCEL CODE REQUIRING INPUT INTO A TEXTBOX RRS feed

  • Question

  • Hi

    I have an excel workbook with a sheet named "Recap" that has several textboxes.  I want these textboxes filled-in by the user.  I found the following code but I am unable to get it to work:

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
     If Trim(TextBox1.Text) = "" Then
     MsgBox "You must enter data"
     Cancel = True
     End If
    End Sub

    Sunday, August 24, 2014 3:12 PM

Answers

  • The Exit event is N/A for an ActiveX textbox on a sheet, in contrast to a textbox on a userform. Maybe this will work for you

    Private Sub TextBox1_LostFocus()
        If Len(TextBox1.Text) = 0 Then
            Me.TextBox1.Activate
            MsgBox "You must enter data"
        End If
    End Sub
    I feel sorry for the user though! What happens if he wants to come back to it later, or in frustration to escape enters something meaningless, a space perhaps

    Sunday, August 24, 2014 9:31 PM
    Moderator