Use the MaxLength property to set the maximum length allowed in each text box
This code checks for required info before adding to the sheet.
Private Sub CommandButton1_Click()
Dim LastRow As Object
Select Case LCase(Left(TextBox3.Text, 2))
Case "aa" To "zz"
Case Else
MsgBox "Invalid Entry", vbInformation
Exit Sub
End Select
If Len(TextBox3.Text) < 4 Then
MsgBox "Invalid Entry", vbInformation
Exit Sub
End If
If Not IsNumeric(TextBox4.Text) Then
MsgBox "Invalid Entry", vbInformation
Exit Sub
End If
Set LastRow = Sheet1.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox3.Text
LastRow.Offset(1, 2).Value = TextBox4.Text
MsgBox "One item added to Main Page"
response = MsgBox("Do you want to enter add another item?", _
vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub
Bookmarks