Excel UserForm issues: Textboxes cannot be blank

  • Thread starter jennifer.trasatti
  • Start date

J

jennifer.trasatti

I'm extremely new to this and I'm trying to use userforms for data
entry on a spreadsheet in excel. Im having issues with some of the data
entry. This is what I have so far:

Private Sub CommandButton1_Click()
ActiveWorkbook.Sheets("Sheet2").Activate
Range("J36").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox1
Range("K36").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select

End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox2
Range("L36").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select

End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox3
Unload Me
CJOForm.Show
End Sub

Private Sub CommandButton2_Click()
ActiveWorkbook.Sheets("Sheet2").Activate
Range("J36").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox1
Range("K36").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select

End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox2
Range("L36").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select

End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Value = TextBox3
Unload Me
End Sub
Private Sub UserForm_Click()
txtName.Value = ""
txtDate.Value = ""
txtName.SetFocus
End Sub

I want it to not let the person skip a textbox without entering some
information in. Right now, If i dont enter in an data, and click the
"done" command button it closes and enters no text but when I open the
form again it acts like there is text entered into the empty cells.
Does this even make sense? I'm not sure if I'm explaining myself well.
Please help! I've been working on this for hours and I just want to be
done!

Jennifer
 
Ad

Advertisements

B

Bob Phillips

Private Sub CommandButton1_Click()
With textbox1
If .Text = "" Then
MsgBox "Must complete textbox1"
.SetFocus
Exit Sub
End If
End With
With textbox2
If .Text = "" Then
MsgBox "Must complete textbox2"
.SetFocus
Exit Sub
End If
End With
With textbox3
If .Text = "" Then
MsgBox "Must complete textbox3"
.SetFocus
Exit Sub
End If
End With
ActiveWorkbook.Sheets("Sheet2").Activate
Range("J36").End(xlDown).Offset(1, 0).Value = textbox1.Text
Range("K36").End(xlDown).Offset(1, 0).Value = textbox2.Text
Range("L36").End(xlDown).Offset(1, 0).Value = textbox3.Text
Unload Me
CJOForm.Show
End Sub

Private Sub CommandButton2_Click()
With textbox1
If .Text = "" Then
MsgBox "Must complete textbox1"
.SetFocus
Exit Sub
End If
End With
With textbox2
If .Text = "" Then
MsgBox "Must complete textbox2"
.SetFocus
Exit Sub
End If
End With
With textbox3
If .Text = "" Then
MsgBox "Must complete textbox3"
.SetFocus
Exit Sub
End If
End With
ActiveWorkbook.Sheets("Sheet2").Activate
Range("J36").End(xlDown).Offset(1, 0).Value = textbox1.Text
Range("K36").End(xlDown).Offset(1, 0).Value = textbox2.Text
Range("L36").End(xlDown).Offset(1, 0).Value = textbox3.Text
Unload Me
End Sub

Private Sub UserForm_Click()
txtName.Value = ""
txtDate.Value = ""
txtName.SetFocus
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top