[RESOLVED] Code Dont work
This Code wont actually enter the data in the workbook any ideas?
Code:
Private Sub Userform_Initialize()
With ComboBox3
.AddItem ""
.AddItem "Mr"
.AddItem "Ms"
.AddItem "Mrs"
.AddItem "Miss"
End With
With ComboBox2
.AddItem ""
.AddItem "Mon"
.AddItem "Tue"
.AddItem "Wed"
.AddItem "Thu"
.AddItem "Fri"
End With
With ComboBox1
.AddItem ""
.AddItem "P"
.AddItem "R"
.AddItem "W"
End With
TextBox1.Value = Worksheets("Main").Range("A1").Value
TextBox2.Value = Worksheets("Main").Range("B1").Value
TextBox3.Value = Worksheets("Main").Range("C1").Value
TextBox4.Value = Worksheets("Main").Range("D1").Value
TextBox5.Value = Worksheets("Main").Range("E1").Value
End Sub
Private Sub CommandButton1_Click()
If Len(Trim(TextBox1.Text)) = o Then
MsgBox "**."
TextBox1.SetFocus
Exit Sub
End If
If Len(Trim(TextBox2.Text)) = o Then
MsgBox "**."
TextBox2.SetFocus
Exit Sub
End If
If Len(Trim(TextBox3.Text)) = o Then
MsgBox "**."
TextBox3.SetFocus
Exit Sub
End If
If Len(Trim(TextBox4.Text)) = o Then
MsgBox "**."
TextBox4.SetFocus
Exit Sub
End If
If Len(Trim(TextBox5.Text)) = o Then
MsgBox "**."
TextBox5.SetFocus
Exit Sub
End If
If Len(Trim(ComboBox1.Text)) = o Then
MsgBox "**."
ComboBox1.SetFocus
Exit Sub
End If
If Len(Trim(ComboBox2.Text)) = o Then
MsgBox "**."
ComboBox2.SetFocus
Exit Sub
End If
If Len(Trim(ComboBox3.Text)) = o Then
MsgBox "**."
ComboBox3.SetFocus
Exit Sub
End If
Set fnd = Sheets("Database").UsedRange.Find(TextBox3.Text)
If Not fnd Is Nothing Then
MsgBox TextBox3.Text & " **"
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
Exit Sub
End If
Select Case ComboBox1.Text
Case "Mr": col = 6
Case "Ms": col = 6
Case "Mrs": col = 6
Case "Miss": col = 6
End Select
Select Case ComboBox2.Text
Case "Mon": col = 7
Case "Tue": col = 7
Case "Wed": col = 7
Case "Thu": col = 7
Case "Fri": col = 7
End Select
Select Case ComboBox3.Text
Case "P": col = 8
Case "R": col = 8
Case "W": col = 8
End Select
lrow = nrow + 49
Do Until IsEmpty(Worksheets("Database").Cells(nrow, col))
nrow = nrow + 1
Loop
Worksheets("Database").Cells(nrow, col).Value = TextBox1.Value
Worksheets("Database").Cells(nrow, col + 1).Value = TextBox2.Value
Worksheets("Database").Cells(nrow, col + 2).Value = TextBox3.Value
Worksheets("Database").Cells(nrow, col + 3).Value = TextBox4.Value
Worksheets("Database").Cells(nrow, col + 4).Value = TextBox5.Value
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
ComboBox1.Text = ""
ComboBox2.Text = ""
ComboBox3.Text = ""
TextBox1.SetFocus
End Sub