如果在文本框中没有输入数据,则会显示错

时间:2016-01-21 08:07:11

标签: excel vba excel-vba

请建议一个vb代码,如果文本框留空,并且在TAB / Enter期间,每个文本框都会显示错误消息框。

Private Sub CommandButton1_Click()
   Sheets("Attendance").Select
   Range("a1").Select
   Do
      If IsEmpty(ActiveCell) = False Then
         ActiveCell.Offset(1, 0).Select
      End If
   Loop Until IsEmpty(ActiveCell) = True

   ActiveCell.Value = Me.d.Value
   ActiveCell.Offset(0, 1).Select
   ActiveCell.Value = Me.N.Value
   ActiveCell.Offset(0, 1).Select
   ActiveCell.Value = Me.Salary.Value
   ActiveCell.Offset(0, 1).Select
   ActiveCell.Value = Me.Remarks.Value
   ActiveCell.Offset(0, 1).Select
   ActiveCell.Value = Me.IT.Value
   ActiveCell.Offset(0, 1).Select
   ActiveCell.Value = Me.Outtime.Value
   ActiveCell.Offset(0, 1).Select
   ActiveCell.Value = Me.Lunch.Value
   ActiveCell.Offset(0, 3).Select
   ActiveCell.Value = Me.Advance.Value
   ActiveCell.Offset(0, 2).Select
   ActiveCell.Value = Me.Paid.Value
End Sub

1 个答案:

答案 0 :(得分:0)

请仔细阅读以下子信息并尝试使用您的用户表单。

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        If Me.TextBox1 = "" Then
            MsgBox "You must enter value!"
            Cancel = True
            Me.TextBox1.SetFocus
        End If
    End Sub